animated scrolling script prevents local anchor positions to be accessed from external links

前端 未结 2 1401
感情败类
感情败类 2020-12-11 18:45

I have a onepager site where I use scrollmagic plus all its necessary plugins/libraries (and jQuery) for different effects where animation, pinning, fading

2条回答
  •  醉梦人生
    2020-12-11 19:07

    You can try and use this code:

    jQuery(function ($) {
        $(document).ready(function() {// if needed, use window.onload which fires after this event
            if(window.location.hash) {
                var hash = window.location.hash;
                $( 'a[href=' + hash + ']' ).click();
            }
        });
    });
    

    It will wait till the DOM (or the page) is loaded and then simulate the user click on the nav item.

    After I've read your question one more time, I am not sure anymore if you want your page loaded on the position of the element which is listed in the anchor or the scroll wasn't working when coming from an external source?

    If the scroll was working but you wanted to display the page at the right place, like a jump, then I propose 2 solutions:

    a) use the CSS opacity:0; on the body and after the scroll is finished, set it back to opacity:1; b) try to jump on the proper place on the page before you load ScrollMagic

提交回复
热议问题