gpt4 book ai didi

jquery - 每个类元素的简单 jquery .hover() 方法

转载 作者:行者123 更新时间:2023-12-01 01:04:25 25 4
gpt4 key购买 nike

没做过太多jquery,遇到了问题。我想为所有具有 .social-tile 类的 div 绑定(bind)悬停事件。我这样做是这样的:

$(function(){
var social_default = $('.social-tile').css('margin-right');
$('.social-tile').each(function(){
$(this).hover(function(){
$(this).animate({
'margin-right': '0px'
},500);
},function(){
$(this).animate({
'margin-right': social_default
},500);
});
});
});

当我将鼠标悬停在一个元素上时,所有 div 的动画都会被触发,并且它们会同时移动。我只想为我悬停的特定元素设置动画。

也许这里有一个非常简单的修复方法,谢谢。

最佳答案

试试这个,抱歉 - 工作演示在这里: http://jsfiddle.net/8vFAD/1/

$('.social-tile').live('mouseover', function(){
$(this).animate({ 'margin-left': '15px'} ,500).animate({ 'margin-left': '30px'} ,500);
});

关于jquery - 每个类元素的简单 jquery .hover() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5518815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com