javascript - jQuery Smooth Scroll to any Anchor -


this question has answer here:

i have tried many different codes smooth scroll anchors. can't find 1 works. needs able scroll vertically, horizontally, , diagonally. problem find others don't seem work multiple targets. want able scroll anchor on page without having edit script.

fiddle

this code matches closest, cant work:

var $root = $('html, body'); $('a').click(function () {      $root.animate({          scrollleft: $($.attr(this, 'href')).offset().left,         scrolltop: $($.attr(this, 'href')).offset().top      }, 500);      return false; }); 

it works in jsfiddle when put on page doesn't

why not duplicate? multi-direction script doesn't target single elements. applies links on page.

i can't jsfiddle work, see if works:

$(function(){     $('a').on({       click:function (e) {         e.preventdefault();         var root = $("html, body");         var target = $(this).attr("href");         root.animate({               scrollleft: $(target).offset().left,             scrolltop: $(target).offset().top         }, 500);       }     }); )}; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -