我使用jQuery编写了一个脚本,以便页面加载时自动滚动到某个id标记。我希望这个动画在页面加载后等待5秒,然后才会触发。我该怎么做呢?
下面是我写的脚本:
let scrollAnchor = "anchor-scroll"
const scrollToAnchor = function(anId){
let aTag = $("#"+anId)
console.log(aTag);
$("html,body").animate({ scrollTop: aTag.offset().top }, 12000);
}
$(document).ready(function () {
scrollToAnchor(scrollAnchor);
});谢谢!
发布于 2020-09-01 17:42:45
您可以使用.delay()函数。All is here -> https://api.jquery.com/delay/ ;)
https://stackoverflow.com/questions/63685063
复制相似问题