jquery Scroll to class name

后端 未结 4 1368
慢半拍i
慢半拍i 2020-12-16 13:33

I have the Html code like below,

4条回答
  •  庸人自扰
    2020-12-16 13:59

    I am using following plain js, please try if you can use it in you codes:

    $('a.smooth-scroll[href*=#]:not([href=#])').click(function () {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top
                }, 1000);
                return false;
            }
        }
    });
    

提交回复
热议问题