jQuery悬停在IE中的粘滞点击/选择问题

时间:2010-07-03 18:12:17

标签: jquery jquery-selectors indexing image-gallery portfolio

我为我的网络投资组合制作了一个“粘贴点击”jquery脚本,该版本适用于Chrome,Opera,Firefox和Safari - 但我仍然遇到一些IE问题。

我有8个缩略图,悬停时在0.3和1不透明度之间淡入淡出。单击时,它使用缩略图的索引显示相应的完整大小图像。它还与一组数字相关联,1-8在悬停时也会从0.3变为1不透明度。

最不清楚的部分是应用悬停的选择。这将按类应用于缩略图/数字,并使用可见图像的索引过滤掉“已点击”的拇指/数字,以便无论悬停如何都保持完全不透明。

使用IE,这种“粘性点击”不起作用,并且所有元素都恢复为悬停行为。我哪里错了? (我不需要它回到IE6或任何东西,但我想至少让当前的IE工作正常。)

<script type="text/javascript">
$(function() {    
    $(".gall").hide();
    $(".gall:first-child").show();
    var thumbs = $(".thumb2,.thumb")
    thumbs.fadeTo(0,0.3);
    $(".thumb2:first-child,.thumb:first-child").fadeTo(0,1);
    var notselected= $(".gall:visible").index();
    $(".thumb:not(#selected),.thumb2:not(#selected2)").hover(function (evt) {$(this).fadeTo(0,1);}, function (evt) {            
                  $(".thumb:gt("+notselected+"),.thumb2:gt("+notselected+"),.thumb:lt("+notselected+"),.thumb2:lt("+notselected+")").fadeTo(0,0.3);
    notselected.hover(function (evt) {notselected.fadeTo(0,1);},function (evt) {notselected.fadeTo(0,0.3);});
    });
    thumbs.click(function() {
        var thumbindex1 = $(".thumb").index(this)
        var thumbindex2 = $(".thumb2").index(this)
        if (thumbindex1>thumbindex2) {var indexboth = thumbindex1}
        else  {var indexboth = thumbindex2}
        var clicked = $(".thumb:eq("+indexboth+"),.thumb2:eq("+indexboth+")")
        var notclicked =  $(".thumb:gt("+indexboth+"),.thumb2:gt("+indexboth+"),.thumb:lt("+indexboth+"),.thumb2:lt("+indexboth+")")
            $("#tryme").html("A " +(indexboth+1)+ " was clicked <br> B "+(indexboth+1)+ " was clicked");  
            clicked.fadeTo(0,1);
            notclicked.fadeTo(0,0.3);
            $(".gall").hide();
            $(".gall:eq("+indexboth+")").show();             
         });
    });

相关的HTML很简单:


有一个容器: DIV类=“包含” 持有DIV类=“画廊”, 主要图像在里面,每个IMG类=“胆” / DIV - 画廊 -

有一个DIV class =“thumbcontainer2”,其中包含数字1-8,每个都在一个单独的DIV类中=“thumb2”

有一个DIV class =“thumbcontainer”,其中包含IMG class =“thumb”中每张缩略图1-8

/ DIV - 包含 -


很抱歉,如果我的jquery代码有点困惑,那是我的第一个jQuery / javascript。我很高兴它现在在所有其他提到的浏览器中都很棒。 任何人都可以看到我在哪里打破Internet Explorer?

提前感谢您的帮助。 -Dan

1 个答案:

答案 0 :(得分:0)

长期和短期是我使用.index()函数的方式让IE混乱。我在另一个论坛中发现了一个建议,用.prevAll(selector)替换.index().size();实现相同的预期结果。这很成功。

我仍然感到困惑的是,当IE在其他浏览器中运行良好时,为什么这是IE的问题。可能我的语法有点可疑。 jslint返回已经定义的变量的问题,其中我使用条件来决定从哪个列表中选择'indexboth'变量。也许与此相关的东西?