我在ready()函数中编写了一个on click jquery函数,但它仍无法在网站上运行。当我在控制台中粘贴代码时,它确实有效。
jQuery(document).ready(function($){
jQuery(".product-video-popup").click(function(){
jQuery("html, body").animate({ scrollTop: 1250 }, 2000);
});
});
答案 0 :(得分:3)
试试这段代码。
jQuery(document).ready(function($){
jQuery(document).on("click",".product-video-popup",function(){
jQuery("html, body").animate({ scrollTop: 1250 }, 2000);
});
});
让我知道它是否有效。当您动态更新DOM时可能会出现这种情况。请检查。
感谢。
答案 1 :(得分:1)
$(document).ready(function(){
$("button").click(function(){
jQuery("div").animate({ scrollTop: 1250 }, 1000);
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
</script>
</head>
<body>
<div style="border:1px solid black;width:100px;height:150px;overflow:auto">
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div><br>
<button>Return the vertical position of the scrollbar</button>
<p>Move the scrollbar down and click the button again.</p>
</body>
</html>
上面的代码工作正常。 我认为你的错误是创建一个DOM元素或不包含jquery库。
我提到工作如下。 Js fiddle link for scroll down