[英]Adding navigation on javascript image slider
So I've been looking for an image slider for my website and I've found a decently simplistic example which I've used but I'm quite stuck on how to add a simple navigation to it. 因此,我一直在寻找网站的图片滑块,并且找到了一个使用过的简单示例,但是我非常想知道如何在其中添加简单的导航。
All I would need is a button to go to the next and previous image. 我只需要一个按钮即可转到下一张和上一张图像。
The code I have : 我的代码:
<script>
function imageData(_imageSrc, _imageTitle){
this.imageSrc = _imageSrc;
this.imageTitle = _imageTitle;
}
var imageSlider_counter = 0;
var imageDataList = new Array();
function Ready(){
document.getElementById("ImageContainer").innerHTML = "<img id='imageSlider-image' src=''/>";
document.getElementById("imageSlider-image").src = imageDataList[imageSlider_counter].imageSrc;
setInterval(function(){
imageSlider_counter = (imageSlider_counter + 1) % imageDataList.length;
document.getElementById("imageSlider-image").src = imageDataList[imageSlider_counter].imageSrc;
},6000);
}
</script>
Here's an image slider that's even more simple and has mostly everything built in: Orbit . 这是一个图像滑块,它更加简单,并且几乎内置了所有内容: Orbit 。
An example of how to set this up would be: 如何进行设置的示例如下:
<div class="small-10 columns">
<ul data-orbit>
<li>
<img src="filelocation1.jpg" alt="Slide 1">
<div class="orbit-caption">
Put text here if you want a caption for your images
</div>
</li>
<li>
<img src="filelocation2.jpg" alt="Slide 2">
</li>
</ul>
</div>
Repeat that format for each image. 对每个图像重复该格式。 Now for functionality. 现在介绍功能。
You must add these scripts: 您必须添加以下脚本:
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/foundation/5.0.2/js/foundation/foundation.js"></script>
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/foundation/5.0.2/js/foundation/foundation.orbit.js"></script>
And you need to start the orbit as well: 您还需要启动轨道:
<script>
$(document).foundation({
orbit: {
animation: 'slide',
timer_speed: 10000,
pause_on_hover: true,
resume_on_mouseout: true,
animation_speed: 500,
navigation_arrows: true,
bullets: true,
next_on_click: true
}
});
$(function () { $(document).foundation(); });
$('#example-orbit').foundation('orbit');
</script>
If you don't want to have a slideshow, but rather just a slider that the user iterates through, get rid of the animation, timer, etc. Hope this helps. 如果您不想播放幻灯片,而只是希望用户反复浏览的滑块,请摆脱动画,计时器等。希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.