简体   繁体   English

在使用jQuery创建并排幻灯片时出现问题

[英]Issue creating side-by-side slideshows with jQuery

I'm trying to create a site with 2 slideshows. 我正在尝试创建一个包含2个幻灯片的网站。 I've tweaked and re-tweaked the JS and Jquery numerous times. 我已经多次调整并重新调整了JS和Jquery。 Sometimes one slideshow works perfectly and the other cycles between one picture, other times both work but are out of sync, or the fadeIn doesn't seem to be applied to the second slideshow, or in some variations one slideshow stays frozen on the initial image and just remains static. 有时一个幻灯片播放效果很好,而另一个在一张图片之间循环,其他时候都可以,但是不同步,或者fadeIn似乎没有应用到第二张幻灯片上,或者在某些变化中,一个幻灯片保持冻结在初始图像上并保持不变。 Anyway, I created a JS Fiddle (link at bottom) and apparently my code is at least free of typos. 无论如何,我创建了一个JS Fiddle(底部的链接),显然我的代码至少没有错别字。 JS is below, the rest is on the JS Fiddle. JS在下面,其余部分在JS小提琴上。 Any help would be greatly appreciated. 任何帮助将不胜感激。

$(document).ready(function () {

    $(".slider #1").fadeIn(1000);
    $(".slider #1").delay(2000).fadeOut(1000);


    var sc = $(".slider img").size();
    var count = 2;

    setInterval(function () {
        $(".slider #" + count).fadeIn(1000);
        $(".slider #" + count).delay(2000).fadeOut(1000);

        if (count === sc) {
            count = 1;
        } else {
            count++;
        }
    }, 3500);


    $(".sliderTwo #7").fadeIn(1000);
    $(".sliderTwo #7").delay(2000).fadeOut(1000);


    var sc2 = 12;
    var count2 = 7;

    setInterval(function () {
        $(".sliderTwo #" + count2).fadeIn(1000);
        $(".sliderTwo #" + count2).delay(2000).fadeOut(1000);

        if (count2 === sc2) {
            count2 = 7;
        } else {
            count2++;
        }
    }, 3500);
});

http://jsfiddle.net/gg4PL/ http://jsfiddle.net/gg4PL/

First:- Never write id as numbers. 第一:-切勿将id写入数字。 try with $(window).load because document.ready always work once the basic html generated, however, window.load work when all the resources loaded into html like images etc... I've seen on js fiddle it's working fine. 尝试$(window).load因为document.ready总是在基本html生成后就可以正常工作,但是,当将所有资源加载到html中(如图像等)时,window.load都可以工作。我在js上看到它工作正常。 What I've done is closed all the <img> tags properly due to which html starts working. 由于html开始工作,我已经正确关闭了所有<img>标记。 Removed document.ready from code and set onload in the left panel of jsfiddle 从代码中删除document.ready并在jsfiddle的左侧面板中设置onload

Selected jquery 1.8.3 in the left panel 在左侧面板中选择了jquery 1.8.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM