开发者

Animate Jquery addClass on hover

开发者 https://www.devze.com 2022-12-24 07:01 出处:网络
I\'m new to Jquery so unsure how i would go about editing the code below to开发者_如何转开发 create a fade in when the class element is hovered over.

I'm new to Jquery so unsure how i would go about editing the code below to开发者_如何转开发 create a fade in when the class element is hovered over.

    <script type="text/javascript">
<!--//--><![CDATA[//><!--     

$(function() {
$('div.work-item').hover(function() {

}).hover(function() {  
$(this).addClass("hover");  
}, function(){  
$(this).removeClass("hover"); 
});  

});
//--><!]]>

Any pointers would be greatly appreciated.

Thanks!


I assume you're fading in some other element when the first is hovered over. Note that hover takes two arguments: a function when the item is hovered over and another when the mouse moves out of the element. Since fadeIn/Out can take some time you might also want to look at the hoverIntent plugin to reduce inadvertent displays when simply mousing over the element and not actually intending to invoke the functionality.

$(function() { 
    $('div.work-item').hover(function() { 
        $('.selector-for-fadein-item').fadeIn('fast');    
    }, function(){   
        $('.selector-for-fadein-item').fadeOut('fast');     
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消