$(function () {
var forum = $('.main-content .statused tr'),
i,
myColors = ["#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#8A4B08","#084B8A","#8A0868","#6A0888","#21610B","#8A0808","#0B4C5F","#5E610B","#210B61"],
myHoverColors=["#FFE8E9","#FFE8E9","#FFE8E9","FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FF8000","#0080FF","#FF0080","#A901DB","#04B404","#FF0000","#01DFD7","#FFFF00","#4000FF"];
for (i = 0; i < myColors.length; i++) {
if (!forum[i]) return;
forum[i].style.backgroundColor = myColors[i];
}
});
上記のコードは動作します (今は下が見えないと思っていました) SO の誰かのおかげで完全にうまくいきました主な背景とともに。これがコード全体を台無しにした私の試みです
$(function () {
var forum = $('.main-content .statused tr'),
i,
myColors = ["#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#FFF","#8A4B08","#084B8A","#8A0868","#6A0888","#21610B","#8A0808","#0B4C5F","#5E610B","#210B61"],
myHoverColors=["#FFE8E9","#FFE8E9","#FFE8E9","FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FFE8E9","#FF8000","#0080FF","#FF0080","#A901DB","#04B404","#FF0000","#01DFD7","#FFFF00","#4000FF"];
for (i = 0; i < myColors.length; i++) {
if (!forum[i]) return;
forum[i].style.backgroundColor = myColors[i];
}
//my hover try
$(forum).hover(function() {
for (i = 0; i < myHoverColors.length; i++) {
if (!forum[i]) return;
forum[i].style.backgroundColor = myHoverColors[i];
}
});
});
カーソルを合わせると、コードが完全に破壊されます。これは、上記の通常のコードで行ったように色を変更しようとしているためだと思います。色の配列で投稿したメインコードのようなホバーカラーを追加する方法について誰か提案がありますか?
機能するカラーコードでもう一度試してください
$(function() {
var forum = $('.main-content .statused tr'),i;
var myColors = ["#000","#F00","#FF0","#FFF","#0F0","#00F"];
var myHoverColors = ["#FF0000","#000","#FFF","#00FF00","#0000ff"];
var i = 0;
for(var j=0;j<forum.length;j++) {
forumBG= forum[j];
if(!forumBG) return;
forum[j].style.background =myColors[i];
if(i == myColors.length -1){
i= 0;
}else{
i++;
}
}
$(forum).on('mouseenter',function() {
for(var j=0;j<forum.length;j++) {
forumBG= forum[j];
if(!forumBG) return;
forum[j].style.background =myHoverColors[i];
if(i == myColors.length -1){
i= 0;
}else{
i++;
}
}
});
$(forum).on('mouseleave',function() {
for(var j=0;j<forum.length;j++) {
forumBG= forum[j];
if(!forumBG) return;
forum[j].style.background =myColors[i];
if(i == myColors.length -1){
i= 0;
}else{
i++;
}
}
});
});