如何使用jQuery为scrollLeft设置动画?
要使用jQuery动画scrollLeft,请使用animate()带有scrollLeft的方法。
示例
您可以尝试运行以下代码,以学习如何使用jQuery动画scrollLeft:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#scrollme').click(function() {
$('html,body').animate({
scrollLeft: $('#demo').css('left')
}, 500, function() {
$('html, body').animate({
scrollLeft: 0
}, 500);
});
});
});
</script>
<style>
#demo {
width: 100px;
height: 100px;
background: green;
position: relative;
left: 800px;
}
</style>
</head>
<body>
<p><button id="scrollme">Click to scroll left</button></p>
<div id="demo"></div>
</body>
</html>热门推荐
10 结婚祝福语简短大气古风
11 情人中秋祝福语简短
12 过年拜年祝福语大全简短
13 毕业祝福语小长句简短
14 新年祝福语简短搞笑创意
15 喜得贵子蛋糕祝福语简短
16 感恩跨年祝福语大全简短
17 男生的生日祝福语简短
18 学生 牛年祝福语大全简短