使用jQuery animate()来增加/减少当前填充



我正试图在悬停时增加/减少div的右侧填充(+=和-=(,并希望获得动画效果。下面的代码正在执行任务,但没有动画。

myDiv.mouseenter( function() {
$(this).css({'padding-right' : '+=35px'});
});
myDiv.mouseleave( function() {
$(this).css({'padding-right' : '-=35px'});
});

附言,animate((函数在使用"-="或"+="值。

提前感谢!

当我检查…时,以下代码在Chrome中运行良好。。。。

<script> 
$(document).ready(function () {
var myDiv = $("#box");
$("#box").mouseenter(function () {
$(this).animate({
'padding-right': '+=35px'
}, 300)
});
$("#box").mouseleave(function () {
$(this).animate({
'padding-right': '-=35px'
}, 300)
});

});
</script>
<div id="box" class="box" style="background-color:red; float:left">Test</div>

最新更新