javascript - Combining functions - jQuery -


Hey guys, I'm new to JS and I'm trying to combine some functions that I made and some New functionality has been added, but I have to move some way

  & lt; Script & gt; Click $ (". 1trigger") (function () {$ (".exe"); Toggle ("blind", 100);}); Click $ (".2trigger") (function () {$ (".exe"); Toggle ("blind", 100);}); Click $ (".3trigger") (function () {$ (".exe 3"); Toggle ("blind", 100);}); $ ("4trigger") Click (function () {$ (". 4 Expand"). Toggle ("blind", 100);}); & Lt; / Script & gt; & Lt; Script & gt; $ (". 1trigger"). Toggle (function () {$ (this) .animate ({backgroundColor: "#fff", color: '# FD0E35'}, 400);}, function () {$ (this) .animate ({backgroundColor: "# FD0E35 ", color: '#fff'}, 400);}); $ (".2trigger") Toggle (function () {$ (this) .animate ({backgroundColor: "#fff", color: '# 00c260'}, 400);}, function () {$ (this) .animate ({backgroundColor: "# 00c260 ", color: '#fff'}, 400);}); $ (".3trigger") Toggle (function () {$ (this) .animate ({backgroundColor: "#fff", color: '# 1f293f'}, 400);}, function () {$ (this). Animate ({background color: # 1f293f ", color: '#ff'}, 400);}); & Lt; / Script & gt;  

What I want to do, makes them simple by adding them and also combines functionality to collapse or undo functions on triggering one of them. So far there is a hard time coming.

Thanks everyone! Use the "include" selector to unify things:

 

// word trigger $ ("[class * = trigger]"). Get the number from the (// function () {// trigger class var number = $ (this) .attr ('class'). (/ (\ D +) trigger) / [1]; // expand that number Adding the class selector to $ ("." + Number + "extension") Toggle ("blind", 100);}); // Store your colors in an array // You may want to use classes to keep your colors. Var colorsArray = ["# FD0E35", "# 00c260", "# 1f293f"]; // Get the number from trigger (function () {// trigger class var number = $ (this) with trigger $ ("[class * = trigger]" in which to connect to all elements of the element .attr ('class') Get the appropriate color from the colors, depending on the number. (/ (\ D +) triggers /) [1]; //, depending on the number. $ (This) .mate ({background color: "#FFF", color: color, number [number - 1]}, 400);}, function () {// above number number var number = $ (this) .attr ('class'). Match (/ (\ d +) trigger) [1] ; $ (This). Value ({background color: color space [ Number-1], color: '#fff'}, 400);});

If you want to reset the expand elements, then I How it will go about depends on your HTML structure.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -