html - Can these two jQuery functions be combined into one that is more efficient? -


I have to hide two functions in jQuery and then show a header, and swap the button so that when The header is hidden, the "Show Title" button appears, and vice versa. They are as follows:

  $ ('# close_header'). Click (function () {$ ('# header'). Animate ({top: '- = 150px'}, 500); $ (this). Toggle (); $ ('# open_header'). Toggle () ;}); $ ('# Open_header') Click (function () {$ ('# header'). Animate ({top: '+ = 150px'}, 500); $ (this) .toggle (); $ ('# Close_header '). Toggle ();});   

The markup to go together is as follows:

  & lt; Img src = "images / close.png" id = "close_header" class = "header_traced fidin button" & gt; & Lt; Img src = "picture / open page" id = "open_header" class = "header_control fadein button" & gt; & Lt; Div id = "header" & gt; * Header content. * & Lt; / Div & gt;   

Is there any way to combine those two functions in one for cleanliness and competencies?

If you try to write it with parameters in a function, it will only be less readable.

Keep it like this, it's okay.

Now answer your question:

Is there any way to combine those two functions ...

Yes

Is there any way to combine those two functions into one for restraint and efficiency?

No. Read the code in other answers, are they down? Are they more efficient? No

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -