javascript - How to call a jQuery function as fast as possible? -


so using php pagination method shown here: how create ajax pagination without database? , have following code menu:

$(document).ready(function(){     $("#my-btn").click(function(event) {         event.preventdefault();         $('html, body').animate({             scrolltop: $("#div").offset().top         }, 2000, "swing", function(){             $("#shiny").effect('shake', {times: 1, direction: 'left', distance: 5}, 300);         });     }); }); 

since portion of page changes have devided menu links bring user different parts of page. example if first page contains element #div user clicks on global template element #my-btn (from menu) , screen scrolls , text shakes once. if button links page? want same effect execute when on page contains different element, example #second-div.

so wonder if there way execute function once user clicks on menu item , moves index.php?limit=1&page=0 index.php?limit=1&page=1 or vise-versa.

there several ways this: use class , specify elements using that.

... scrolltop: $('.myclass').offset().top ...

or pass in id part of function when click (meaning you'd have specify every page:

<a id="my-btn" href="javascript:void();" data-div="#second-div">scroll button</a>  <script> $(function() {     $("#my-btn").click(function(event) {         event.preventdefault();         var divtoanimate = $(this).data('div');         $('html, body').animate({             scrolltop: $(divtoanimate).offset().top         }, 2000, "swing", function(){             $("#shiny").effect('shake', {times: 1, direction: 'left', distance:                  5}, 300);         });     }); }); </script> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -