M
M
mfedchuk2015-11-11 18:36:41
JavaScript
mfedchuk, 2015-11-11 18:36:41

How to undo anchor move?

There is an anchor. It is necessary that when you click on the corresponding link, the hash is added to the address bar, and the physical scroll is not carried out. Here is what I found on the Internet and put together into one. Works with bugs. Is there a more general solution?

$('a[href^="#img"]').bind('click.smoothscroll',function (e) {
    e.preventDefault();

    var target = this.hash,
    $target = $(target);

    $('html, body').stop().animate({
        'scrollTop': window.pageYOffset});
        window.location.hash = target;
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-11-11
@mfedchuk

$('a[href^="#img"]').on("click.smoothscroll", function(e) {
    e.preventDefault();
    location.hash = this.hash;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question