Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let scrollTOId = function(scrollToId){
- // Figure out element to scroll to
- let target = $(scrollToId);
- console.log(target);
- // Does a scroll target exist?
- if (target.length) {
- // Only prevent default if animation is actually gonna happen
- event.preventDefault();
- $('html, body').animate({
- scrollTop: target.offset().top - 70
- }, 1000, function() {
- // Callback after animation
- // Must change focus!
- let $target = $(target);
- $target.focus();
- if ($target.is(":focus")) { // Checking if the target was focused
- return false;
- } else {
- $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
- $target.focus(); // Set focus again
- };
- });
- }
- }
- //
- const scrollId = $('#element_Id');
- scrollTOId(scrollId);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement