gpt4 book ai didi

jquery - 单击 jQuery 时向左水平滚动 + 50px

转载 作者:行者123 更新时间:2023-12-01 01:17:10 26 4
gpt4 key购买 nike

我试图使用 jQuery 使左箭头和右箭头在单击时左右滚动 +50px,但它似乎只是将页面重置为向左滚动 0。

这是我的 HTML:

<div id="parallax">
<a href="#" id="test"></a>
</div>

这是我的脚本:

$(document).ready(function(){
$("#test").click(function(){
$("#parallax").scrollLeft(5000);
});
});

任何帮助或见解将不胜感激。

最佳答案

您需要阻止 <a> 的默认操作元素,作为 href="#"将始终滚动到顶部:

$(document).ready(function(){
$("#test").click(function(e){
e.preventDefault();
$('body').scrollLeft(5000);
});
});​

FIDDLE

关于jquery - 单击 jQuery 时向左水平滚动 + 50px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11959019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com