0

因此,当新访客到达网站时,起始图像将是“background3.jpg”,而不是从“background1.jpg”开始

在下方,您可以在控制幻灯片的索引页面上看到我正在使用的脚本。

<script>
   $.backstretch([
  "imgs/background1.jpg",
  "imgs/background2.jpg",
  "imgs/background3.jpg",
  "imgs/background4.jpg",
  "imgs/background5.jpg" ], {
    fade: 800,    //Speed of Fade
    duration: 2500     // The length of Time the image is display
});

4

2 回答 2

0

在此处下载 jquery-cookie 插件:链接

<script>
    $(document).ready(function(){
        if($.cookie("IsNew").length==0){
            $.cookie("IsNew","somevalue");
            $.backstretch(["imgs/background1.jpg",
                          "imgs/background2.jpg",
                          "imgs/background3.jpg",
                          "imgs/background4.jpg",
                          "imgs/background5.jpg"], 
                          {fade: 800, duration :2500 });
        }
        else
        {
            $.backstretch(["imgs/background3.jpg",
                          "imgs/background1.jpg",
                          "imgs/background2.jpg",
                          "imgs/background4.jpg",
                          "imgs/background5.jpg"], 
                          {fade: 800, duration :2500 });
        }
    });
</script>
于 2013-09-16T12:20:51.040 回答
0

您可以只测试 cookie 是否存在:

if($.cookie(cookie_name)){
    $.backstretch(
        "imgs/background1.jpg",
        "imgs/background2.jpg",
        "imgs/background3.jpg",
        "imgs/background4.jpg",
        "imgs/background5.jpg", {
            fade: 800,    //Speed of Fade
            duration: 2500     // The length of Time the image is display
    });
} else {
    //your server sends the cookies here
    dont_show_slides();
}
于 2013-09-16T12:17:08.247 回答