jQuery类的更改(不更新)

时间:2014-03-27 07:05:53

标签: jquery

我制作了一个幻灯片,它使用了两个类(定位)和ID(样式),现在当我移动图像时,我正在改变它的类;但是当mouseenter(类)被触发时,jQuery仍在读取旧的html,其中.pc1是某个图像但现在是另一个。

有解决方法吗?

我试图使用它:

$(document).find('.pccenter').mouseenter(function(){
    if (loading != true) {
        $(this).fadeTo(1000, 1);
        $(this).parent().children('.shinepc').fadeTo(2000, 0.4);
    }
});






var position ="";
var shinepos = "";
$('.pccenter').mouseover(function(){
    position = $(document).find('.pccenter').attr('id');
    shinepos = $(document).find('.shinepc').attr('id');
    console.log(shinepos);
    console.log(position);
    if (loading != true) {
        $('#' + position).fadeTo(1000, 1);
         $('#' + shinepos).fadeTo(2000, 0.4);
    }
});

$('.pccenter').mouseleave(function(){
    position = $(document).find('.pccenter').attr('id');
    shinepos = $(document).find('.shinepc').attr('id');
    if (loading != true) {
        $('#' + position).fadeTo(1000, 0.6);
        $('#' + shinepos).fadeTo(3000, 0.2);
    }
});

尝试使用:

<div class="pcmidr" id="pcmidr"><div class="shinepcmidr" id="shinepcmidr"></div></div>
<div class="pccenter" id="pccenter"><div class="shinepc" id="shinepc"></div></div>

现在上课&#34; pcmidr&#34;对pccenter和pccenter的更改更改为pcmidl。

$(document).find('.pccenter').mouseleave(function(){
    if (loading != true) {
        $(this).fadeTo(1000, 0.6);
        $(this).parent().children('.shinepc').fadeTo(3000, 0.2);
    }
});

2 个答案:

答案 0 :(得分:0)

使用mouseover事件而不是mouseenter

当指针移动到子元素时,

mouseover会触发,而只有当指针移动到绑定元素时,mouseenter才会触发。

答案 1 :(得分:0)

$(document).find('.pccenter').mouseover(function(){
    if (loading != true) {
        $(this).fadeTo(1000, 1);
        $(this).parent().children('.shinepc').fadeTo(2000, 0.4);
}
});

$(document).find('.pccenter').mouseleave(function(){
    if (loading != true) {
        $(this).fadeTo(1000, 0.6);
        $(this).parent().children('.shinepc').fadeTo(3000, 0.2);
    }
});