ページがあり、コンテナ内のデータを次のようにスクロールしたかった: http://jsfiddle.net/pXy2C/。
複数の div を使用してスクロールできるテキストの列を隣り合わせに作成しました。今...これらの各divで、コンテナを次のdivまたは前のdivにスクロールするボタンを作成したいと思います。上記の jsfiddle の例の問題は、最初と最後の 200px のみをロールオーバーすることです。必要なことを行うためにオフセットを取得する方法はありますか?
私の試みはここhttp://jsfiddle.net/3xgSX/ですが、下にも貼り付けます。
助けてくれてありがとう。
CSS:
#container{
width:1000px;
height:500px;
overflow:hidden;
Position:relative;border:1px #000 solid;
}
#contents{
width:1000px;
height:200px;
position:absolute;
top:0;
left:0;
}
HTML:
<!--Column 1-->
<div style='float:left; width:150px'>
Put your content here...
<button id="left">Left</button>
<button id="right">right</button>
</div><!--end div colomn 1-->
<!--Column 2-->
<div style='float:left; width:150px; margin-left:300px'>
Put another content here...
<br>
<button id="left">Left</button>
<button id="right">right</button>
</div><!--End div column2-->
</div><!--End div "contents"-->
Javascript:
<script type="text/javascript">
$(document).ready(function(){
$("#right").click(function(){
$("#contents").animate({left:'-200px'},500);
$("#container").animate({'margin-left':'200px'},500);
});
$("#left").click(function(){
$("#contents").animate({left:'0px'},500);
$("#container").animate({'margin-left':'0px'},500);
});
});
</script>