Javascript-每次单击元素时提供的div
我一直在努力解决一个有点令人沮丧的简单问题。我需要一个div,以便在每次单击按钮时向右移动更多Javascript-每次单击元素时提供的div,javascript,jquery,css,Javascript,Jquery,Css,我一直在努力解决一个有点令人沮丧的简单问题。我需要一个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. &l
<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>
//这里是图库内容
//每次单击此按钮时,将库向左移动590px。
//按钮,每次单击时将库向右移动590px。
您可以在jquery.animate()的帮助下实现这一点
这是你的电话号码
参考是
HTML
JS
您可以根据需要更改left的值。希望这有帮助。谢谢!这正是我要找的!很高兴知道。如果答案有帮助,请接受!我会的,必须先等4分钟!您的
moveLeft()
和moveRight()
方法声明在哪里?问题现在已经得到了回答,我将继续使用onclick。
<button id="left">«</button>
<button id="right">»</button>
<div class="block"></div>
div {
position: absolute;
background-color: #abc;
left: 50px;
width: 90px;
height: 90px;
margin: 5px;
}
$( "#right" ).click(function() {
$( ".block" ).animate({ "left": "+=50px" }, "slow" );
});
$( "#left" ).click(function(){
$( ".block" ).animate({ "left": "-=50px" }, "slow" );
});