我没有做太多的jquery,遇到了一个问题。我想为所有div绑定类.social-tile的鼠标悬停事件。我是这样做的:
$(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的动画都会被触发,并且它们会同时移动。我只想让我悬停的特定元素具有动画效果。
也许这里有一个非常简单的修复方法,谢谢。
发布于 2011-04-02 05:09:31
$(function() {
$('.social-tile').hover(
function() {
$(this).data('prev-margin-right', $(this).css('margin-right') );
$(this).animate({
'margin-right': '0px'
}, 500);
}, function() {
$(this).animate({
'margin-right': $(this).data('prev-margin-right')
}, 500);
});
});发布于 2011-04-02 05:13:35
试试看,对不起--演示在这里:http://jsfiddle.net/8vFAD/1/
$('.social-tile').live('mouseover', function(){
$(this).animate({ 'margin-left': '15px'} ,500).animate({ 'margin-left': '30px'} ,500);
});发布于 2011-04-02 05:06:34
好的,你的变量social_default,里面有.socialtile,它会调用所有分配给它的div,把它改成(this)。
https://stackoverflow.com/questions/5518815
复制相似问题