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

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -