jQuery设置对象动画,使其看起来像漂浮在水中的对象
所以我对jQuery还比较陌生,我正在尝试制作一个漂浮在水中的冰山的连续动画 这是水上的冰山。 我想让它旋转,鲍勃,这是我目前的循环动画代码。。只是需要一些帮助,让它做我想要的哈jQuery设置对象动画,使其看起来像漂浮在水中的对象,jquery,css,animation,jquery-animate,Jquery,Css,Animation,Jquery Animate,所以我对jQuery还比较陌生,我正在尝试制作一个漂浮在水中的冰山的连续动画 这是水上的冰山。 我想让它旋转,鲍勃,这是我目前的循环动画代码。。只是需要一些帮助,让它做我想要的哈 function iceburg() { jQuery('.iceburg').css({bottom:0}); jQuery('.iceburg').animate ({ bottom: '10px' }, 200, function() { jQuery('
function iceburg() {
jQuery('.iceburg').css({bottom:0});
jQuery('.iceburg').animate ({
bottom: '10px'
}, 200, function() {
jQuery('.iceburg').animate ({
bottom: '0px'
}, 200);
});
}
iceburg();
我不知道我做错了什么,怎么旋转它?有人能帮忙吗?如果你想让效果。。。环使用
setInterval
另外,在回调中使用
$(this)
,而不是第二次使用jQuery('.iceburg')
,如果希望效果。。。环使用setInterval
另外,在回调中使用$(this)
,而不是第二次使用jQuery('.iceburg')
var ice = $('.iceburg');
function anim() {
setInterval(function(){
ice.animate({
top:'+=20'},
{
duration:1000,
step:function()
{ ice.css('-webkit-transform','rotate(-0.5deg)');}
});
ice.animate({
top:'-=20'},
{
duration:1000,
step:function()
{ ice.css('-webkit-transform','rotate(0.5deg)');}
});
});
}
anim();
拉小提琴试试
var ice = $('.iceburg');
function anim() {
setInterval(function(){
ice.animate({
top:'+=20'},
{
duration:1000,
step:function()
{ ice.css('-webkit-transform','rotate(-0.5deg)');}
});
ice.animate({
top:'-=20'},
{
duration:1000,
step:function()
{ ice.css('-webkit-transform','rotate(0.5deg)');}
});
});
}
anim();
Fiddle同意@TCHdvlp的优化意见。每次使用
jQuery('.iceburg')
时,jQuery都会遍历DOM以查找具有该类的每个元素。最好使用这个jQuery对象创建一个变量,然后重新使用它。你会有更好的表现!同意@TCHdvlp的优化意见。每次使用jQuery('.iceburg')
时,jQuery都会遍历DOM以查找具有该类的每个元素。最好使用这个jQuery对象创建一个变量,然后重新使用它。你会有更好的表现!非常有帮助!正是我要找的!遗憾的是,你不能流畅地设置“旋转”的动画,对吗?@LeviCole你可以尝试一些放松库,它可以帮助:)非常有用!正是我要找的!遗憾的是,你不能流畅地设置“旋转”的动画,对吗?@LeviCole你可以尝试一些放松库,它可以帮助:)