Answers for "css smooth scroll to id"

CSS
2

smooth scroll to id

// Select all links with hashes
$('a[href*="#"]')
  // Remove links that don't actually link to anything
  .not('[href="#"]')
  .not('[href="#0"]')
  .click(function(event) {
    // On-page links
    if (
      location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') 
      && 
      location.hostname == this.hostname
    ) {
      // Figure out element to scroll to
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
      // 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
        }, 1000, function() {
          // Callback after animation
          // Must change focus!
          var $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
          };
        });
      }
    }
  });
Posted by: Guest on January-10-2021
1

smooth scrolll to id js

// handle links with @href started with '#' only
$(document).on('click', 'a[href^="#"]', function(e) {
    // target element id
    var id = $(this).attr('href');

    // target element
    var $id = $(id);
    if ($id.length === 0) {
        return;
    }

    // prevent standard hash navigation (avoid blinking in IE)
    e.preventDefault();

    // top position relative to the document
    var pos = $id.offset().top;

    // animated top scrolling
    $('body, html').animate({scrollTop: pos});
});
Posted by: Guest on January-04-2021
0

css smooth scroll to id

<style>
        @@keyframes animateright{from{right:-300px;opacity:0} to{right:0;opacity:1}}
    </style>         

   $(document).on('click', 'a[href^="#"]', function (e) {
                // target element id
                var id = $(this).attr('href');

                // target element
                var $id = $(id);
                if ($id.length === 0) {
                    return;
                }

                // prevent standard hash navigation (avoid blinking in IE)
                e.preventDefault();

                // top position relative to the document
                var pos = $id.offset().top;

                // animated top scrolling
                $('body, html').animate({ scrollTop: pos });

              // remove css from element
                $('.dataTables_wrapper').css({ 'position': 'unset', 'animation': 'unset' });
         	
			  // add the class or element you want to make css  
    		  $(id).next('.dataTables_wrapper').css({ 'position': 'relative', 'animation': 'animateright 1.5s' })
            });
Posted by: Guest on May-19-2021

Browse Popular Code Answers by Language