-1

我在这里有一段代码可以工作,但不确定为什么我的淡入淡出对身体不起作用,如果您认为我遇到了什么问题,请告诉我谢谢

    <script type="text/javascript">
$(window).load(function() {
    var lastSlide = "";
    $('#slider').nivoSlider({
        effect: 'random',
        directionNavHide : true,
        slices : 15,
        animSpeed : 500,
        pauseTime : 6000,
        controlNav : false,
        pauseOnHover : true,
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        beforeChange: function(){
            if(lastSlide == "images/header_used.jpg") {  //use the bg image of the slide that comes before the newslide
                $("body").attr("style","background: #000 url(images/bg.jpg) top center no-repeat;").fadeIn("slow");
            } else {
                $("body").attr("style","background: #ADADAD url(images/bgnd_grad.jpg) repeat-x;").fadeOut("slow");
            }
        },
        afterChange: function() {
            t = $(this).children("a:visible");
            lastSlide = $("img", t).attr("src");
        }
    });
});
</script>
4

3 回答 3

0

这是因为“lastSlide”变量可以存储多个对象(一个来自img,一个来自可见链接)。

 t = $(this).children("a:visible");
 lastSlide = $("img", t).attr("src");  //could store multiple source.

这使比较有点棘手,并且可能会产生错误。

再加上你用最糟糕的方式来塑造你的身体。正如其他人所说,使用类或 .css jQuery 函数 (http://api.jquery.com/css/)。

希望这有帮助

于 2012-10-21T22:00:57.757 回答
0

淡入淡出对身体有效,绝对。正如Reflective所说, $("body").css("background","#000 url(images/bg.jpg) top center no-repeat;").fadeOut("slow") 如果仍然不起作用,您应该查看您的nivoSlider函数

于 2012-10-22T05:48:24.780 回答
0

虽然它可以用身体背景解决你的任务。相反,我会使用 addClass 和 removeClass。您正在操作也显示/隐藏使用它的样式属性。

我无法测试它,但如果你将淡入淡出切换到 show() 和 hide() 会发生什么,只是为了确定延迟是否是一个因素.. :)

于 2012-10-21T21:18:59.473 回答