我一直在努力解决一个有点令人沮丧的简单问题。每次点击一个按钮,我都需要一个div来向右移动。
<div class="gallery">
//Gallery content here
</div>
<div class="arrow-m-left" onClick="moveLeft()">
//Button to move the gallery left by 590px each time this is clicked.
</div>
<div class="arrow-m-right" onClick="moveRight()">
//Button to move the gallery right by 590px each time this is clicked.
</div>
答案 0 :(得分:0)
您可以在jquery .animate()的帮助下实现这一目标。
以下是example
参考是here
HTML
<button id="left">«</button>
<button id="right">»</button>
<div class="block"></div>
CSS
div {
position: absolute;
background-color: #abc;
left: 50px;
width: 90px;
height: 90px;
margin: 5px;
}
JS
$( "#right" ).click(function() {
$( ".block" ).animate({ "left": "+=50px" }, "slow" );
});
$( "#left" ).click(function(){
$( ".block" ).animate({ "left": "-=50px" }, "slow" );
});
您可以根据需要更改左侧的值。希望这会有所帮助。