【发布时间】:2021-11-11 10:47:21
【问题描述】:
我在我的代码中使用 intro.js 来实现演练。我想实现一个场景,在单击完成按钮(.introjs-donebutton)时,页面应该滚动到顶部,但是使用此代码它没有发生。谁能帮我解决这个问题?
//$('.col-new-four').attr('id','essentials');
const intro = introJs();
intro.setOptions({
steps:[
{
element:'#featured_apps_2_0',
intro:'welcome'
},
{
element:'#myTopnav',
intro:'Quickly access the apps and portals you need on and off the clock.'
},
{
element:'.slideshow-container',
intro:'This space features topics you care about the most.'
},
{
element:'.card',
intro:'Stay up-to-date on trending stories.'
},
{
element:'#stepextra',
intro:'View your recommended and favorite pages.'
},
{
element:'#step4',
intro:'Find promotional content, latest additions and more here.'
},
{
element:'#essentials2',
intro:'Learn about what’s trending with your favorite topics.'
},
{
element:'.col-new-7525',
intro:'Explore benefits, tools and new features available to you.'
}
]
})
$('.introjs-donebutton').click(function() {
$(window).scrollTop(0);
});
function callintro(){
intro.start();
console.log("called intro")
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/4.2.2/intro.min.js"></script>
【问题讨论】:
-
试试$(document).scrollTop(0);
-
也可以试试 $('body').scrollTop(0)
-
你的 HTML 在哪里?
-
或者您可以完全跳过 jquery 并通过尝试“window.scrollTo(0, 0);”来简单地使用本机 JS
-
似乎不起作用
标签: javascript jquery button click intro.js