简体   繁体   English

在模态启动之前,如何使用“简单模态”滚动到页面顶部?

[英]How can I use Simple Modal to scroll to the top of my page just before the modal launches?

I'm successfully using Simple Modal to launch a modal when a button is clicked, however, I want the page to scroll to the top first. 单击按钮时,我已成功使用“简单模态”启动模态,但是,我希望页面首先滚动到顶部。 I tried placing an anchor tag at the top of the page and referencing it in my link using , but it didn't work. 我尝试将锚标记放置在页面顶部,并使用引用我的链接,但这没有用。 The Simple Modal still worked, but it didn't scroll to the top of the page first. Simple Modal仍然有效,但没有先滚动到页面顶部。 Is there a way to edit the simple modal javascript to make it first scroll to the top of the page before the modal is opened? 有没有一种方法可以编辑简单的模式JavaScript,使其在模式打开之前先滚动到页面顶部?

Use a callback: http://www.ericmmartin.com/projects/simplemodal/#options 使用回调: http : //www.ericmmartin.com/projects/simplemodal/#options

$('#modalContent').modal({
    onOpen: function () {
        $('html, body').scrollTo(0, 0);
    }
});

在调用模态之前使用JavaScript: window.scrollTo(0,0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何滚动到模式的顶部 - How to scroll to the top of a modal 如何在 React 的 Modal 组件中滚动到顶部? - How can I scroll to the top in a Modal component in React? 在我的 function 在用户批准后执行另一个步骤之前,如何使用模态作为附加步骤? - How can I use a modal as additional step before my function executes another upon user approval? 如何在我简单的AngularJs控制器中使用Modal - how to use a Modal in my simple AngularJs controller 如何将第二个模态放在第一个模态的顶部? - How can I position the second modal on top of the first modal? 如何在我的Web应用程序中使用单个模式,并避免每个页面上出现重复的html? - How can I use a single modal across my web application and avoid repetative html on every page? 如何在我的 web 页面中隐藏或显示引导模式? - How can I hide or show a bootstrap modal in my web page? 我如何创建一个函数,以便当主体阻止滚动时,模式窗口中的内容滚动到顶部? - How can I create a function so that the content in a modal window scrolls to top when body prevents scroll? 如何在另一个 html 页面中使用引导模式? - How I can use bootstrap Modal in another html page? Bootbox模式滚动到打开页面的顶部 - Bootbox modal scrolls to top of page before opening
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM