2012-05-17 154 views
0

我试图给子菜单添加一个不错的效果,但我不能使用marginLeft,因为它会弄乱容器。所以我试图通过使用left而不是marginLeft,但我无法得到它的工作......任何想法为什么?jQuery向左移动

$('#order_list li').hover(function(){ 
    $(this).stop().animate({ "left": "14px" }, 250, function() { 
    $(this).animate({ "left": "10px" }, 250); 
    }); 
},function(){ 
    $(this).stop().animate({ "left": "4px" }, 250, function() { 
    $(this).animate({ "left": "0px" }, 250); 
    }); 
}); 
+0

你的效果是把“礼”向左移动后的一些事件是什么呢? – sree

回答

4

CSS Left仅适用于positioned元素。

尝试将position:relative;添加到li

例如

#order_list li { 
    position: relative; 
} 
0
$('#order_list li').hover(function(){ 
    $(this).stop().animate({ "textIndent": "14px" }, 250, function() { 
    $(this).animate({ "textIndent": "10px" }, 250); 
    }); 
},function(){ 
    $(this).stop().animate({ "left": "4px" }, 250, function() { 
    $(this).animate({ "textIndent": "0px" }, 250); 
    }); 
});