简体   繁体   中英

Bootstrap smooth scrolling to Anchor - jScript not working

I'm using Twitters Bootstrap, I want to have smooth scrolling to my Anchors, but it won't work. This is at the end of my document, jut before the </body> tag:

<script type="text/javascript">
!function ($) {
    $(function(){
        $('#running-box, #bg-car').carousel({});

        var $root = $('html, body');

        $('a').click(function() {
            var href = $.attr(this, 'href');
            $root.animate({
                scrollTop: $(href).offset().top
            }, 500, function () {
                window.location.hash = href;
            });
            return false;
        });
    })
}(window.jQuery)

</script>   

jQuery and Bootstrap are included correctly...

If you replace

 'a[href*=#]:not([href=#])' 

with

'a[href*=#]:not([href=#]):not([href=#idname])'

you can prevent the smooth scrolling from working for that one specific link,

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