1

我创建了一个页面,分为七个部分和每个页面上的两个列 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>
4

1 回答 1

1

要将多个功能分配给单击,您可以从现有功能中调用一个功能,或创建一个专门用于调用其他 2 个功能的新功能。

于 2013-02-19T16:50:38.900 回答