3
\$\begingroup\$

How can I make this code snippet be improved to become more professional?

(function($){
 $.fn.showMenu = function(options){
 return this.each(function(){
 $this = $(this);
 var high = $this.outerHeight(),
 scrollHeight = $this.get(0).scrollHeight;
 $this.bind('mouseenter',function(){
 $this.css({overflow:'visible'})
 .stop()
 .animate({height:scrollHeight},'fast');
 }).bind('mouseleave',function(){
 $this.animate({height:high}, function(){
 $this.css({overflow:'hidden'});
 });
 });
 });
 }//the end of $.fn.showMenu
 $('#theme_content').showMenu();
});
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Sep 6, 2012 at 15:16
\$\endgroup\$
1
  • \$\begingroup\$ Have you considered using CSS animations instead? \$\endgroup\$ Commented Sep 17, 2012 at 16:10

2 Answers 2

1
\$\begingroup\$

You could also use .hover, if you are going for shorter code. Jquery Hover

answered Sep 6, 2012 at 18:11
\$\endgroup\$
1
\$\begingroup\$
  1. Proper Indentation. You shouldn't need the //end of fn comment. Just indent that entire block.

  2. $this = $(this) needs a var statement.

  3. You wrap your code in a function, which is good, but you need to call that function. The last line should be })();

answered Sep 14, 2012 at 14:12
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.