2012-03-30 105 views
0

查看标题。它似乎加载得很好,并很好地转换成一张图片,但之后拒绝工作。jQuery幻灯片在自定义WordPress模板中的一张图片后停止

当我使用Chrome浏览器检查并查看出了什么问题时,它告诉我它无法识别slideSwitch功能,即使我在本地测试它时工作正常。

无论如何,我希望这里的主人在stackoverflow将能够帮助我的无力的头脑自我。

在此先感谢。

jQuery代码:

$(function slideSwitch() { 
    var $active = $('#slideshow img.active'); 

    if ($active.length == 0) $active = $('#slideshow img:last'); 

    var $next = $active.next().length ? $active.next() : $('#slideshow img:first'); 

    $active.addClass('last-active'); 

    $next.css({ 
     opacity: 0.0 
    }).addClass('active').animate({ 
     opacity: 1.0 
    }, 2000, function() { 
     $active.removeClass('active last-active'); 
    }); 
}); 

$(function() { 
    setInterval("slideSwitch()", 5000); 
}); 

下面是它附带的CSS:

#slideshow { 
    height:327px; 
    border:thick #000; 
    list-style:none; 
    margin:0px auto; 
    width:600px; 
    overflow: hidden; 
    position:relative; 
} 

#slideshow img { 
    border: solid #000000 10px; 
    display:block; 
    position:absolute; 
    z-index: 8; 
} 

#slideshow img.active { 
    z-index:10; 
} 

#slideshow img.last-active { 
    z-index:9; 
} 
+0

哎你能弹出在一些HTML中,也许能够帮助你,欢呼!如果你不能给HTML看这里的例子 - **工作** http://jsfiddle.net/skelly/D6BGj/(和振作起来,兄弟,大家都很好,包括你,所以没有人是软弱的头脑:) – 2012-03-30 07:18:52

回答

0

因为setInterval的是一个eval。

所以做到这一点:

window.setInterval(function() { 
    slideSwitch(); 
}, 5000); 

参见:http://jsfiddle.net/cxPU6/

在这里阅读更多:window.setInterval from inside an object

我一遍又一遍的得到同样的问题:)

+0

是啊!谢谢!完美解决!如果有某种方式可以通过网络给你一个苹果或其他东西,我肯定会这样做。 – thedoorbehindyourmind 2012-03-30 18:51:59

+0

我喜欢苹果! :) – 2012-03-31 12:49:55

0

尝试:

setInterval(function(){ 
    slideSwitch(); 
}, 5000);