2012-06-19 68 views
0

我有一些运行JavaScript图像翻转的代码,我是新来的JS,我需要图像翻转时,如果我徘徊和悬停,如果我把它放在它每翻转一次鼠标是翻转移动,而不是当鼠标关闭时。JavaScript图片翻转

下面是代码:

$(document).ready(function() { 
    setInterval(function() { 
     $('.sponsorFlip').load('script.js'); 
     $('.sponsorFlip').load('jquery.flip.min.js'); 
    }, 30000); 
    $('.sponsorFlip').one("mouseenter mouseleave", function() { 
     var elem = $(this); 
     if (elem.data('flipped')) { 
      elem.revertFlip(); 
      elem.data('flipped', false) 
     } 
     else { 
      elem.flip({ 
       direction: 'rl', 
       speed: 250, 
       onBefore: function() { 
        elem.html(elem.siblings('.sponsorData').html()); 
       } 
      }); 
      elem.data('flipped', true); 
     } 
    }); 
    $('.sponsorFlip').bind("click", function() { 
     var elem = $(this); 
     if (elem.data('flipped')) { 
      elem.revertFlip(); 
      elem.data('flipped', false) 
     } 
     else { 
      elem.flip({ 
       direction: 'rl', 
       speed: 250, 
       onBefore: function() { 
        elem.html(elem.siblings('.sponsorData').html()); 
       } 
      }); 
      elem.data('flipped', true); 
     } 
    }); 
}); 
+2

你能提供一个[jsbin](http://www.jsbin.com)或[的jsfiddle](http://www.jsfiddle.net)例子? – acme

回答

1

利用类。 )预览 - http://jsfiddle.net/TJZmM/3/

$('div').bind('mouseover mouseout', function(){ 
    var self = $(this); 

    if(self.toggleClass('flipped').hasClass('flipped')) { 
     self.html('rl'); 
    } 
    else { 
     self.html('lr'); 
    } 
});​