On page load, if URL hash matches one of the values in the array, scroll to the element with the matching data-load-id attribute

后端 未结 1 813
别那么骄傲
别那么骄傲 2021-01-26 02:52

I currently have the following:

var scrollingAnchorIds = [];
    var getTheseIds = $(\".anchor-content\").each(function() {
        scrollingAnchorIds.push($(th         


        
相关标签:
1条回答
  • 2021-01-26 03:34

    When thinking about it, most of your code seems excessive. Try something like this:

    $(function(){
        $('html,body').animate({scrollTop: $("[data-load-id='" + window.location.hash + "']").offset().top - 50},850);
    });
    

    I made a fiddle also, though window.location.hash does not work in this.

    0 讨论(0)
提交回复
热议问题