I have an image slider on my page. I want to code a previous and next button. I believe the code I have is correct but for some reason event.stopPropagation is not working.
<div class="slider-wrapper">
<div id="slider">
<img id="1" class="slider-image" data-image-num="1" src="images/slider/Pictures/Heaslip.jpg" alt="Overflow: Hidden No More" />
<img id="2" class="slider-image" data-image-num="2" src="images/slider/Pictures/BOD.jpg" alt="HTML Captions" />
<img id="3" class="slider-image" data-image-num="3" src="images/slider/Pictures/Kidney.jpg" alt="and more features" />
<img id="4" class="slider-image" data-image-num="4" src="images/slider/Pictures/kearney.jpg" alt="and more features" />
</div>
<div id="slider-nav">
<a href="#" class="left" onclick="prev(); return false;">Previous</a>
<a href="#" class="right" onclick="next(); return false;">Next</a>
</div>
</div>
jQuery
function prev(event){
event.stopPropagation();
var newSlide = sliderInt - 1;
showSlide(newSlide);
}
The prvious button .left is still causing the browser to jump back to the top of the page. I assumed that event.stopPropagation stops this from happening.
Any Ideas? Thanks
如果您仍然想知道, event.preventDefault()
是您要寻找的内容,则可以防止浏览器应用默认链接行为。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.