Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to use .hover and .click on same element
  2. $(function () {
  3.     $('.more').hover(function () { //Open on hover
  4.         $('#pull_down_content').animate({
  5.             'top': '-360px'
  6.         }, 1000);
  7.     }, function () { //Close when not hovered
  8.         $('#pull_down_content').animate({
  9.             'top': '-380px'
  10.         }, 1000);
  11.     });
  12. });
  13. $('.more').click(function () { //Move down when clicked
  14.     $('#pull_down_content').animate({
  15.         'top': '0px'
  16.     }, 1000);
  17. });
  18.        
  19. $(function() {        
  20.     $('.more').hover(function(){    //Open on hover
  21.            $('#pull_down_content').animate({'top':'-360px'},1000);
  22.         },    
  23.         function(){   //Close when not hovered
  24.            if (!$('#pull_down_content').hasClass("expanded"))
  25.                $('#pull_down_content').animate({'top':'-380px'},1000);    
  26.         });
  27.     });
  28.     $('.more').click(function(){    //Move down when clicked
  29.         $('#pull_down_content').addClass("expanded").animate({'top':'0px'},1000);
  30.     });
  31.        
  32. $(function() {
  33.     $('.more').on('mouseenter mouseleave click', function(e) {
  34.         if (!$(this).data('clicked')) {
  35.             var Top = e.type==='mouseenter' ? '-360px' : e.type==='click' ? '0px' : '-380px';
  36.             $('#pull_down_content').stop().animate({'top': Top}, 1000);
  37.             if (e.type==='click') $(this).data('clicked', true);
  38.         }else{
  39.             if (e.type==='click') {
  40.                 $(this).data('clicked', false);
  41.                 $('#pull_down_content').stop().animate({'top': '-380px'}, 1000);
  42.             }
  43.         }
  44.     });
  45. });