Redirect to a div on a different page with smooth scrolling?

后端 未结 8 1162
悲哀的现实
悲哀的现实 2021-01-01 15:33

Question Background:

I have a 2 page website. Both pages use the same masterlayout.cshtml page which features a Navbar. Within the

8条回答
  •  既然无缘
    2021-01-01 16:18

    You can try something like this. I have changed data-id to id. You can use javascript.

    
    

    Javascript to scroll

    function scrollme(id)
    {
         var scrollElem = scrollableElement('html', 'body');
         var targetOffset = $(id).offset().top;
          $(scrollElem).animate({scrollTop: targetOffset-100}, 1000, function() {
    
              });
    }
    function scrollableElement(els)
    {
        for (var i = 0, argLength = arguments.length; i  0) {
            return el;
          } else {
            $scrollElement.scrollTop(1);
            var isScrollable = $scrollElement.scrollTop()> 0;
            $scrollElement.scrollTop(0);
            if (isScrollable) {
              return el;
            }
          }
        }
        return [];
    }
    

提交回复
热议问题