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

Popular posts from this blog

iis - ASP.Net Core CreatedAtAction in HttpPost action returns 201 but entire request ends with 500 -

gcc - Neither ld wrap nor LD_PRELOAD working to intercept system call -

ssh - Vagrant Windows - ssh_exchange_identification: read: Connection reset by peer -