重置此jQuery动画 [英] Reset THIS jQuery animation

查看:94
本文介绍了重置此jQuery动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着看看



如何重置jquery动画以重新开始?



但是在这种情况下似乎无效。 / p>

我正尝试重新启动此 Kinetic Animation

有效,但重置动画对象没有。



我缺少什么? 现在代码下面的工作似乎



DEMO



CODE

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 dtd> 
< html xmlns =http://www.w3.org/1999/xhtml>

< head>
< meta content =text / html; charset = utf-8http-equiv =Content-Type/>
< title> jQuery Powered Kinetic Text Animation< / title>
< link href =http://demo.campolar.me/Kinetic-Animation/css/font-face.css =stylesheettype =text / css/>
< link href =http://demo.campolar.me/Kinetic-Animation/css/style.css =stylesheettype =text / css/>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js>< / script>
< script type =text / javascript>
function animation(){

//我尝试重置
$('。first')。removeAttr('style');
$('。second')。removeAttr('style');
$('。shadow1')。removeAttr('style');
$('。second .a')。removeAttr('style');
$('。second .b')。removeAttr('style');
$('。second .c')。removeAttr('style');
$('。third')。removeAttr('style');
$('。fourth')。removeAttr('style');
$('。fifth')。removeAttr('style');
$('。fifth .a')。removeAttr('style');
$('。fifth .b')。removeAttr('style');
$('。fifth .c')。removeAttr('style');
$('。fifth .d')。removeAttr('style');
$('。sixth')。removeAttr('style');
//结束重置尝试

//原始代码

$('。first')。animate({right:'1500px'},3000);
$('。first')。animate({left:'1000px'},500);
$('。shadow1')。delay(3800).show(1000);
$('。second .a')。delay(3800).show(500);
$('。second .b')。delay(4000).show(500);
$('。second .c')。delay(4200).show(500);
$('。third')。delay(6200).animate({bottom:'125px'},500);
$('。shadow1')。delay(1800).hide(500);
$('。second .a')。delay(3500).animate({bottom:'30px'},300);
$('。second .b')。delay(3800).animate({bottom:'30px'},300);
$('。second .c')。delay(4100).animate({bottom:'30px'},300);
$('。second')。delay(10000).hide(500);
$('。third')。delay(3500).animate({top:'125px'},500);
$('。fourth')。delay(10500).show(500);
$('。fifth .a')。delay(12000).animate({left:'85px'},300);
$('。fifth .b')。delay(12300).animate({left:'95px'},300);
$('。fifth .c')。delay(12600).animate({left:'180px'},300);
$('。fifth .d')。delay(12900).animate({left:'100px'},300);
$('。fourth')。delay(4000).animate({'font-size':'150px','bottom':'50px','right':'50px'},300);
$('。fifth')。delay(15000).hide(500);
$('。fourth')。delay(2000).hide(500);
$('。sixth')。delay(18000).show(1000,function(){
setTimeout(animation,2000)
}
}
$(function(){
animation()
});

< / script>
< / head>

< body>

< div id =wrapper>
< h1>使用jQuery的动力学文本动画< / h1>
< p>欢迎使用jquery制作小动力学动画。它不包括许多奇特的东西,但这只是我想尝试,看起来
像我做的。要播放此内容,请点击下面的播放按钮(不可见?启用javascript或等待加载)。您需要启用javascript
和支持浏览器的@ font-face。< / p>
< p>动画在黑框中工作,大小为650x400像素。所以确保
屏幕的可见部分适合它。这将至少
1024x768像素分辨率。< / p>
< p>< a href =http://campolar.me/2010/05/kinetic-text-animation-using-jquery/>在这里阅读全文!< / a> < / p>
< p>我希望你喜欢:)< / p>
< p class =play>< img src =images / play.pngalt =播放/>播放!< / p&
< / div>
< div class =animationwindow>
< div class =first nevis>
你知道吗?< / div>
<! - 从隐藏的左侧滑动到隐藏的右侧 - >
< div class =second museo>
< div class =a>
WHAT< / div>
< div class =b>
THIS< / div>
< div class =c>
IS?< / div>
< / div>
< div class =shadow1>
< / div>
< div class =third museo>
你知道吗? < / div>
< div class =fourth nevis>
否? < / div>
< div class =fifth museo>
< div class =a>
Are< / div>
< div class =b>
You< / div>
< div class =c>
Kidding< / div>
< div class =d>
Me?< / div>
< / div>
< div class =sixth museo>
这是一个动画动画,使用< br />
< span> jQuery !!!< / span> < / div>
< / div>
< div id =CampolarDesigns>
< / div>

< / body>

< / html>


解决方案

This:

  $('。sixth')。delay(18000).show(1000,
setTimeout
animation()
},2000));

只是指:

  $('。sixth')。delay(18000).show(1000,timeoutIdThatReturnedBySetTimeoutFunction); // 
setTimeout(function(){//我改变循环动画
animation()
},2000);

这就是为什么, animation



可能你需要这个属性:

你的属性会在动画过程中被恢复,而不是在动画结束后被恢复。

  $('。sixth')。delay(18000).show(1000,function(){
setTimeout {// my change to loop the animation
animation()
},2000);
});

或:

 code> $('。sixth')。delay(18000).show(1000,function(){
setTimeout(animation,2000);
}

在这种情况下,动画之后将会完成,而不是开始(您现在正在做什么)。


I tried to look at

how to reset a jquery animation to start over?

but that did not seem to work in this case.

I am trying to restart this Kinetic Animation by adding the function as a callback on the last show.

That worked, but resetting the animated objects did not.

What am I missing? - Now the code below does work it seems

DEMO

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>jQuery Powered Kinetic Text Animation</title>
<link href="http://demo.campolar.me/Kinetic-Animation/css/font-face.css" rel="stylesheet" type="text/css" />
<link href="http://demo.campolar.me/Kinetic-Animation/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
function animation() {

   // my attempt to reset
        $('.first').removeAttr('style');
        $('.second').removeAttr('style');
        $('.shadow1').removeAttr('style');
        $('.second .a').removeAttr('style');
        $('.second .b').removeAttr('style');
        $('.second .c').removeAttr('style');
        $('.third').removeAttr('style');
        $('.fourth').removeAttr('style');
        $('.fifth').removeAttr('style');
        $('.fifth .a').removeAttr('style');
        $('.fifth .b').removeAttr('style');
        $('.fifth .c').removeAttr('style');
        $('.fifth .d').removeAttr('style');
        $('.sixth').removeAttr('style');
   // end reset attempt

   // original code

        $('.first').animate({right: '1500px'}, 3000);
        $('.first').animate({left: '1000px'}, 500);
        $('.shadow1').delay(3800).show(1000);
        $('.second .a').delay(3800).show(500);
        $('.second .b').delay(4000).show(500);
        $('.second .c').delay(4200).show(500);
        $('.third').delay(6200).animate({bottom: '125px'}, 500);
        $('.shadow1').delay(1800).hide(500);
        $('.second .a').delay(3500).animate({bottom: '30px'}, 300);
        $('.second .b').delay(3800).animate({bottom: '30px'}, 300);
        $('.second .c').delay(4100).animate({bottom: '30px'}, 300);
        $('.second').delay(10000).hide(500);
        $('.third').delay(3500).animate({top: '125px'}, 500);
        $('.fourth').delay(10500).show(500);
        $('.fifth .a').delay(12000).animate({left: '85px'}, 300);
        $('.fifth .b').delay(12300).animate({left: '95px'}, 300);
        $('.fifth .c').delay(12600).animate({left: '180px'}, 300);
        $('.fifth .d').delay(12900).animate({left: '100px'}, 300);
        $('.fourth').delay(4000).animate({'font-size': '150px', 'bottom': '50px', 'right': '50px'}, 300);
        $('.fifth').delay(15000).hide(500);
        $('.fourth').delay(2000).hide(500);
        $('.sixth').delay(18000).show(1000,function() {
                setTimeout(animation,2000)
            });
}
$(function() {
  animation()   
});

</script>
</head>

<body>

<div id="wrapper">
    <h1>Kinetic Text Animation using jQuery</h1>
    <p>Welcome to my try at making a small kinetic animation using jquery. It doesn&#39;t 
    include many fancy things, but this is just something i wanted to try and looks 
    like I&#39;ve done it. To play this, click the play button below (not visible? Enable javascript or wait for it to load). You need javascript 
    enabled and a @font-face supporting browser.</p>
    <p>The animation works in the black box, which is 650x400 pixels. So make sure 
    the visible portion of your screen fits it. This will be fine on a least of 
    1024x768 pixel resolution.</p>
    <p><a href="http://campolar.me/2010/05/kinetic-text-animation-using-jquery/">Read the whole article here!</a></p>
    <p>I hope you like it :)</p>
    <p class="play"><img src="images/play.png" alt="Play" />Play!</p>
</div>
<div class="animationwindow">
    <div class="first nevis">
        Do you know?</div>
    <!-- slides from hidden left to hidden right -->
    <div class="second museo">
        <div class="a">
            WHAT</div>
        <div class="b">
            THIS</div>
        <div class="c">
            IS?</div>
    </div>
    <div class="shadow1">
    </div>
    <div class="third museo">
        DO YOU KNOW? </div>
    <div class="fourth nevis">
        No? </div>
    <div class="fifth museo">
        <div class="a">
            Are</div>
        <div class="b">
            You</div>
        <div class="c">
            Kidding</div>
        <div class="d">
            Me?</div>
    </div>
    <div class="sixth museo">
        This is a kinetic animation, achieved using <br />
        <span>jQuery!!!</span> </div>
</div>
<div id="CampolarDesigns">
</div>

</body>

</html>

解决方案

This :

$('.sixth').delay(18000).show(1000,
setTimeout(function() { // my change to loop the animation
  animation()
},2000));

simply means:

$('.sixth').delay(18000).show(1000, timeoutIdThatReturnedBySetTimeoutFunction); //
setTimeout(function() { // my change to loop the animation
  animation()
},2000);

That is why, animation will be called earlier than your animation will be fully completed.This means your attributes will be restored during the animation, not the after its end.

Probably you need this:

$('.sixth').delay(18000).show(1000,function(){
    setTimeout(function() { // my change to loop the animation
       animation()
    },2000);
});

or:

$('.sixth').delay(18000).show(1000,function(){
    setTimeout( animation, 2000 );
});

In this case the animation will be repeated after it will be finished, not when it will be started (what's you are doing now).

这篇关于重置此jQuery动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆