简体   繁体   中英

Link with hashtag

I need something link this

$(function() {
    $('a[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-55
                }, 1000);
                return false;
            }
        }
    });
});

But it works only for that link <a href="#offer">offer</a> . I want that this code works for this link for example <a href="offer.html#offer2">offer2</a>

I think your jquery selector is wrong.

See http://jsfiddle.net/9shvmhwh/5/

 $(function() {
       $("a[href*='#']:not([href='#'])").click(function(event) {
            location = $(this).attr('href');
            event.stopPropgation();
            return true;
       });
    });

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