C
C
Captain Cocoa2015-11-21 14:19:42
css
Captain Cocoa, 2015-11-21 14:19:42

Anchor link without url replacement, how to do this?

Hello everyone, we all know how to make simple anchor links in html

<div id="top"></div>
<a href="#top">на верх</a>

But in this case, this will be added to the address bar
/#top
. The essence of the question is, is it possible to somehow make anchor links without changing the url ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2015-11-22
@RadCor

Page scroll to id is used to navigate through landing blocks

V
Vitaly Inchin ☢, 2015-11-21
@In4in

Element.onclick = function(e){
   e.preventDefault();
   document.querySelector(this.hash).scrollIntoView();
}

Y
Yaroslav Samardak, 2015-11-21
@yaroslav_samardak

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

    var target = $(this.hash);
    $('html, body').stop().animate({
        'scrollTop': target.offset().top
    }, 500);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question