code_junkie

Need help refactoring a simple jquery animation script

Nov 12th, 2011
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $("#footer").dblclick(showStatusBar);
  4. });
  5. function showStatusBar() {
  6. var footer = $("#footer");
  7. footer.unbind('dblclick', showStatusBar);
  8. footer.animate({ height: "100px" }, 200);
  9. footer.dblclick(hideStatusBar);
  10. footer.bind('mouseleave', hideStatusBar);
  11. }
  12.  
  13. function hideStatusBar() {
  14. var footer = $("#footer");
  15. footer.unbind('mouseleave', hideStatusBar);
  16. footer.unbind('dblclick', hideStatusBar);
  17. footer.animate({ height: "11px" }, 200);
  18. footer.dblclick(showStatusBar);
  19. }
  20. </script>
  21.  
  22. // NOTE: Untested!
  23. function statusBarToggle() {
  24. /* Starts as hidden. */
  25. if(this.isHidden == undefined)
  26. this.isHidden = true;
  27.  
  28. this.isHidden = !this.isHidden;
  29.  
  30. var newHeight = this.isHidden ? 11 : 200;
  31.  
  32. $(this)
  33. .stop()
  34. .animate({ height: newHeight + 'px' }, 200);
  35.  
  36. /* When mouse leaves open status bar, close it. */
  37. if(this.isHidden)
  38. $(this).unbind('mouseleave', statusBarToggle);
  39. else
  40. $(this).bind('mouseleave', statusBarToggle);
  41. }
  42.  
  43. $(document).ready(function() {
  44. // ...
  45. $('#footer').dblclick(statusBarToggle);
  46. }
Add Comment
Please, Sign In to add comment