我创建了一个页面,分为七个部分和每个页面上的两个列 div。当我单击右按钮时,我滚动到下一列,当我单击左侧时,我滚动到左列。问题是,假设我在第一页,我从第二列滚动到第三列,我离开了页面,必须手动移动 x 滚动条。有没有办法我可以只编程按钮来强制 x 溢出?
谢谢
CSS
<style>
#contents {
width: 3500px; <!--Total size of the large container-->
height: 200px;
position: absolute; }
#container {
height: 500px;
overflow: hidden;
position: relative;
border: 1px #000 solid;
}
#container, .col {
width: 500px;<!--total size of each column.-->
}
.col {
float: left;
}
</style>
HTML
<!--Column 1-->
<div class="col">
<p>Put your content here...</p>
<button class="left">Left</button>
<button class="right">right</button>
</div><!--end div column 1-->
我又做了 6 列。
JAVASCRIPT
<script>
var colwidth = $('#container').width(),
contwidth = $('#contents').width(),
getOffset = function() {
return parseInt($('#container').css('margin-left'));
};
$(".left").click(function(){
if (getOffset() === 0) return false;
$("#contents").animate({left: '+=' + colwidth},500);
$("#container").animate({'margin-left': '-=' + colwidth},500);
});
$(".right").click(function(){
if (getOffset() === contwidth - colwidth) return false;
$("#contents").animate({left: '-=' + colwidth},500);
$("#container").animate({'margin-left': '+=' + colwidth},500);
});
</script>