简体   繁体   中英

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. 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?

Use a callback: http://www.ericmmartin.com/projects/simplemodal/#options

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM