javascript - Making Reusable Function in Jquery -
i use code , makes website load.
$('#start').click(function() { $('html,body').animate({ scrolltop : $('.scroll').offset().top },1500);//end animate });//end click
i used change #start
, .scroll
everytime. tips?
wrap in function.
function foo(startelem, scrollelem) { $(startelem).click(function() { $('html,body').animate({ scrolltop : $(scrollelem).offset().top },1500);//end animate }); }
then call when need it.
foo('#start', '.scroll');
read more here.
Comments
Post a Comment