A
A
Alexander26982018-02-03 15:35:19
JavaScript
Alexander2698, 2018-02-03 15:35:19

How to implement a smooth transition on the anchor link?

there is a menu

<ul class="menu-order">
            <li>
              <a href="#1">1</a>
            </li>
            <li>
              <a href="#2">2</a>
            </li>
            <li>
              <a href="#3">3</a>
            </li>
            <li>
              <a href="#4">4</a>
            </li>
          </ul>

and blocks with corresponding id. How to implement a smooth transition to an anchor?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VelAnna, 2018-02-03
@AnnaVel

$(document).on('click', '.menu-order li a', function() {
  var linkID = $(this).attr('href');
  $('html, body').animate({ 
    scrollTop: $(linkID).offset().top 
  }, 'slow');
});

A
Alexander Kositsyn, 2018-02-04
@alex_keysi

HERE is a link to codepen on native, the function is for all occasions

G
Glorious Cat, 2018-02-03
@tansur

$(".menu-order li a").click(function() {
    $("html, body").animate({
      scrollTop: $($(this).attr("href")).offset().top + "px"
    }, {
      duration: 750,
      easing: "swing"
    });
    return false;
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question