【发布时间】:2012-11-27 12:33:05
【问题描述】:
诚然,我是 jQuery 的新手,但我知道一点 javascript,我正在尝试用几个动画来为 div 设置动画。
我希望 div 首先移动到页面的中心 然后我希望它到达中心后翻转然后展开。
我遇到的麻烦是使用.animate() 方法更改div 的top 和left 属性以使其居中。
问题是 moveToCenter 函数中的 .animate 方法实际上并没有动画到中心的移动,它只是跳过动画部分(属性更改,但更改不是动画)并继续进行翻转和休息。
谁能告诉我为什么会这样/我哪里出错了?
如何(如果有的话)修复?
HTML
<div id="flip" style="background-color:#ff0000;
width:200px;
height:200px;
position:absolute">
<h4> printf("Hello World"); </h4>
</div>
JS
function moveToCenter()
{
$('#flip').animate({'top':'300','left':'300'});
}
$(document).ready(function() {
$('#flip').click( function() {
moveToCenter(); //function that is supposed to moves the div to the center
$(this).flip({
content: 'Scanf()',
color: '#00FF00',
direction: 'lr',
onEnd: function(){ $('#flip').animate({
'height' : '400', 'width': '300'
}
,'500','swing');
lol(); //Another function that does some other animations
}
});
});
});
【问题讨论】:
标签: javascript jquery jquery-ui jquery-animate