我想在我的页面上放置5个div,但页面的宽度不允许我这样做。所以我认为我只能展示其中的3个,而想要看到其他人的人可以点击左右箭头来查看。我希望它以这种方式工作非常简单。有人知道最好的方法吗?
答案 0 :(得分:9)
以下是使用jQuery.DIYslider,轻量级和可自定义的jQuery滑块的方法。
以下代码的演示:http://jsfiddle.net/bj4yZ/155/
你会注意到这个插件可以很容易地做任何你想做的事情。
您可以在上面链接的页面上找到所有这些插件的选项,方法和事件。
<强> HTML 强>
<button id="go-left">«</button> <button id="go-right">»</button>
<div class="slider"><!-- The slider -->
<div><!-- A mandatory div used by the slider -->
<!-- Each div below is considered a slide -->
<div class="a">Div #1</div>
<div class="b">Div #2</div>
<div class="c">Div #3</div>
<div class="d">Div #4</div>
<div class="e">Div #5</div>
</div>
</div>
<强>的JavaScript 强>
$(".slider").diyslider({
width: "400px", // width of the slider
height: "200px", // height of the slider
display: 3, // number of slides you want it to display at once
loop: false // disable looping on slides
}); // this is all you need!
// use buttons to change slide
$("#go-left").bind("click", function(){
// Go to the previous slide
$(".slider").diyslider("move", "back");
});
$("#go-right").bind("click", function(){
// Go to the previous slide
$(".slider").diyslider("move", "forth");
});
答案 1 :(得分:1)
对你来说编码并不难,所以理论就像这样
html结构
.outter-container
.inner container
.slide slide1
.slide slide2
.slide slide3
.slide slide4
.slide slideX