Sunday, 15 February 2015

javascript - Long code into function? -



javascript - Long code into function? -

this code has no errors in page, i'm not looking help there. i'm curious if there shorter way this, there's lot of code beingness repeated class names beingness changed each time. create shorter in function or loop of sort? thanks

//menu $('.aboutone').click(function(){ $.scrollto('.basicsrow', 1000, {axis:'yx'}); $.scrollto('.basicsrow', 1000, {axis:'xy'}); }) $('.abouttwo').click(function(){ $.scrollto('.storyrow', 1000, {axis:'yx'}); $.scrollto('.storyrow', 1000, {axis:'xy'}); }) $('.aboutthree').click(function(){ $.scrollto('.teamrow', 1000, {axis:'yx'}); $.scrollto('.teamrow', 1000, {axis:'xy'}); }) $('.aboutone').click(function(){ $.scrollto('.basicsrow', 1000, {axis:'yx'}); $.scrollto('.basicsrow', 1000, {axis:'xy'}); }) $('.abouttwo').click(function(){ $.scrollto('.storyrow', 1000, {axis:'yx'}); $.scrollto('.storyrow', 1000, {axis:'xy'}); }) $('.aboutthree').click(function(){ $.scrollto('.teamrow', 1000, {axis:'yx'}); $.scrollto('.teamrow', 1000, {axis:'xy'}); }) $('.titleone').click(function(){ $.scrollto('.homerow', 1000, {axis:'yx'}); $.scrollto('.homerow', 1000, {axis:'xy'}); }) $('.docsone').click(function(){ $.scrollto('.startrow', 1000, {axis:'yx'}); $.scrollto('.startrow', 1000, {axis:'xy'}); }) $('.docstwo').click(function(){ $.scrollto('.pinpointrow', 1000, {axis:'yx'}); $.scrollto('.pinpointrow', 1000, {axis:'xy'}); }) $('.docsthree').click(function(){ $.scrollto('.swiperow', 1000, {axis:'yx'}); $.scrollto('.swiperow', 1000, {axis:'xy'}); }) $('.docsfour').click(function(){ $.scrollto('.restrow', 1000, {axis:'yx'}); $.scrollto('.restrow', 1000, {axis:'xy'}); }) $('.docsfive').click(function(){ $.scrollto('.actionrow', 1000, {axis:'yx'}); $.scrollto('.actionrow', 1000, {axis:'xy'}); }) $('.contactone').click(function(){ $.scrollto('.contactrow', 1000, {axis:'yx'}); $.scrollto('.contactrow', 1000, {axis:'xy'}); }) $('.downloadone').click(function(){ $.scrollto('.downloadrow', 1000, {axis:'yx'}); $.scrollto('.downloadrow', 1000, {axis:'xy'}); })

perhaps set object, pass function:

var els = { '.abouttwo':'.teamrow', '.aboutthree':'.homerow', ... }; function menu(els){ $.each(els, function(a,b){ $(a).click(function(){ $.scrollto(b, 1000, {axis: "yx"}); $.scrollto(b, 1000, {axis: "yx"}); }); }); } // phone call menu(els);

should give manageability - if changes modify els object.

note: take chance point out it's suggested utilize jquery's .on() (docs) binding events.

javascript jquery css loops scrollto

No comments:

Post a Comment