简体   繁体   English

幻灯片与图库导航冲突

[英]Slideshow conflicting with gallery navidation

So I'm not an experienced coder but I wanted to put together my little gallery. 所以我不是一个有经验的编码员,但是我想把我的小画廊放在一起。 I have an automatic slideshow that changes the picture every 7 seconds and arrows on each side of the image to navigate through the slides. 我有一个自动幻灯片放映,每7秒更改一次图片,并在图像的每一侧更改箭头以浏览幻灯片。 Its working fine except I would like the 7 second counter to reset if the image is changed, and I don't seem to be able to figure that out. 它的工作正常,除了如果图像更改我希望7秒计数器重置,而且我似乎无法弄清楚。

My HTML is 我的HTML是

<div class="slide" id="slide1" style="background-image: url(images/pattern.png), url(images/header.jpg);">
    <section id="header" class="dark">
        <header>
            <h1>title</h1>
                <div>
                <div style="float: left"><a href="#" onClick="MM_showHideLayers('slide3','','show','slide2','','hide','slide1','','hide')"><img src="prevImgBtn.png"></div><div style="float: right;"><img src="nextImgBtn.png"></div>
                <div style="clear: both;">
                </div>
            <p>Description text</p>
        </header>
        <footer>
            <a href="externallink.com" target="_blank" class="button">Check out</a>
        </footer>
        <div class="arrow-wrapper"><a  class="arrow" href="#work"><img border="0" width="5%" height="5%" src="images/arrow.svg" /></a></div>
    </section>
</div>
<div class="slide" id="slide2" style="background-image: url(images/pattern.png), url(images/header2.jpg);">
    <section id="header2" class="dark">
        <header>
            <h1>Title 2</h1>
                <div>
                <div style="float: left"><a href="#" onClick="MM_showHideLayers('slide1','','show','slide2','','hide','slide3','','hide')"><img src="prevImgBtn.png"></div><div style="float: right;"><img src="nextImgBtn.png"></div>
                <div style="clear: both;">
                </div>
                <p>Description.</p>
        </header>
        <footer>
            <a href="anotherlink.com" target="_blank" class="button scrolly">Know More</a>
        </footer>
        <div class="arrow-wrapper"><a  class="arrow" href="#work"><img border="0" width="5%" height="5%" src="images/arrow.svg" /></a></div>
    </section>
</div>
<div class="slide" id="slide3" style="background-image: url(images/pattern.png), url(images/header3.jpg);">
    <section id="header2" class="dark">
        <header>
            <h1>Title 3</h1>
                <div>
                <div style="float: left"><a href="#" onClick="MM_showHideLayers('slide2','','show','slide1','','hide','slide3','','hide')"><img src="prevImgBtn.png"></div><div style="float: right;"><img src="nextImgBtn.png"></div>
                <div style="clear: both;">
                </div>
            <p>yet another description</p>
        </header>
        <footer>
            <a href="biography.html" class="button scrolly">Know More</a>
        </footer>
        <div class="arrow-wrapper"><a  class="arrow" href="#work"><img border="0" width="5%" height="5%" src="images/arrow.svg" /></a></div>
    </section>
</div>

And the JS 和JS

</script>
<script type="text/javascript">
jQuery(function () {
    var $els = $('div[id^=slide]'),
        i = 0,
        len = $els.length;

    $els.slice(1).hide();
    setInterval(function () {
        $els.eq(i).fadeOut(function () {
            i = (i + 1) % len
            $els.eq(i).fadeIn();
        })
    }, 7000)
})
</script>
<script type="text/javascript">
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}
</script>

Thanks for any help 谢谢你的帮助

assign the interval to a var, and on image change clear the interval and set it again: 将间隔分配给var,并在图像更改时清除间隔并再次设置:

var my7sInterval = setInterval(function () {
    $els.eq(i).fadeOut(function () {
        i = (i + 1) % len
        $els.eq(i).fadeIn();
    })
}, 7000)

//on image change
clearInterval(my7sInterval);
//.. set the interval again using the above

or... 要么...

set an interval that will count down seconds and switch as it reaches 7 in count. 设置一个间隔,该间隔将倒数秒,并在计数达到7时切换。 and on image change you simply reset the counter: 在图片更改时,您只需重置计数器即可:

var s7Timeout = 0;
setInterval(function () {
    if (s7Timeout >= 7) {
        s7Timeout = 0;
        $els.eq(i).fadeOut(function () {
            i = (i + 1) % len
            $els.eq(i).fadeIn();
        })
    } else {
        s7Timeout++;
    }
}, 1000)

//and on image change reset the counter:
s7Timeout=0;

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

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