我正在使用backstretch jquery在我的网站上循环图像。我可以让图像循环正常,但我正在尝试添加“下一个”和“上一个”按钮,但我无法让它们工作。
当我单击下一个按钮时,什么也没有发生。
我的下一个按钮如下所示:
<a id="next" href="#"><img src="/images/arrow-right.png">
我将我所有的 jquery 代码放在页面底部的 body 关闭标记之前。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.backstretch.js"></script>
<script>
    var images = [
    "/images/backgrounds/Image01.jpg",
    "/images/backgrounds/Image02.jpg",
    "/images/backgrounds/Image03.jpg"
    ];
    $(images).each(function() {
       $('<img/>')[0].src = this; 
    });
    // The index variable will keep track of which image is currently showing
    var index = 0;
    $.backstretch(images[index], {speed: 500});
    $('#next').click(function(x) {
        x.preventDefault();
        $('body').data('backstretch').next();
    });
    $('#prev').click(function(x) {
        x.preventDefault();
        $('body').data('backstretch').prev();
    });
</script >
使用萤火虫调试,我得到这个:
    TypeError: $(...).data(...) is undefined
    $('body').data('backstretch').next();