与setinterval的jquery横幅

时间:2013-09-22 12:18:50

标签: jquery setinterval banner

我为一个网站设计了一个简单的jquery横幅。横幅工作正常,但如何使用设置间隔自动刷新横幅。我已经完成了各种代码,但它无法正常工作。请通过纠正特定间隔的横幅代码重复来帮助我。

CSS代码:

 .banner {-webkit-border-radius:6px;    -moz-border-radius:8px;    
              border-radius:8px; -khtml-border-radius: 8px; 
              border:#bbd9ef solid 1px; background:#f5fffa; 
              padding: 5px 0 0 20px; width: 200px; height: 110px; 
             }
  .k, .l, .m, .n {position: relative; top: -200px; text-decoration: none; }
  .n { font-weight: bold; color: red; }

使用jquery1.9.1的脚本代码:

$(document).ready(function() {
    $(".banner a").hide();
    (function() {
        $(".k").show().animate({
            top: "0"
        }, 3000, function() {
            $(".l").show().animate({
                top: "0"
            }, 3000, function() {
                $(".m").show().animate({
                    top: "0"
                }, 3000, function() {
                    $(".n").show().animate({
                        top: "0"
                    }, 3000);
                });
            });
        });
    })();
});

HTML代码:

<div class="banner">
    <a href="#" class="k">Design banner in your ownway</a><br />
    <a href="#" class="l"> Get more taffic and publishers.</a><br/>
    <a href="#" class="m">Still doubt, please do contact:</a><br/><br/>
    <a href="#" class="n">www.freemenu.info</a>
</div>

1 个答案:

答案 0 :(得分:0)

显示元素n后,设置计时器以重新启动动画

$(document).ready(function () {
    $(".banner a").hide();
    function banner(){
        $(".k").show().animate({
            top: "0"
        }, 3000, function () {
            $(".l").show().animate({
                top: "0"
            }, 3000, function () {
                $(".m").show().animate({
                    top: "0"
                }, 3000, function () {
                    $(".n").show().animate({
                        top: "0"
                    }, 3000, function(){
                        setTimeout(function(){
                            $(".banner a").hide().css('top', '');
                            banner();
                        }, 5000);
                    });
                });
            });
        });
    }
    banner();
});

演示:Fiddle