jquery - 如何在调用隐藏div时启动jquery动画?

标签 jquery css animation

我有一个隐藏的 div,其中有一个运行打字机动画的 jquery。我想知道一旦显示 div,我如何才能开始动画?在显示 div 的那一刻,类型已经存在。

这是现在本质上发生的事情 http://jsfiddle.net/caW8d/

$(document).ready(function()                         
/*-----------------FADE EFFECT --------------------*/
    {   var synopsis = $('#synopsis');
function runIt() {
   synopsis.animate({opacity:'+=1'}, 1000);
   synopsis.animate({opacity:'-=0.9'}, 2000, runIt).delay(2000);
}
       runIt(); 

    $("#trigger1").mouseover(function () {
   $("#somethingThere").fadeIn('slow');
});
    $("#trigger1").mouseout(function() {
    $("#somethingThere").fadeOut('slow');
});
    $("#trigger1").click(function () {
   $("#caption").fadeIn('slow');
});
    $("#caption").click(function () {
   $("#caption").hide();
});

/*-----------------TYPERWRITER EFFECT --------------------*/    
      $.fn.typer = function(options) {
        var defaults = {speed: 50},
            settings = $.extend({}, defaults, options);
        return this.each(function(e,options){
            var el = $(this), 
                text = el.html(), 
                chars = 0, 
                timeout = null, 
                tw = function() {
                    el.html(text.substr(0, chars));
                    chars += 1;
                    timeout = setTimeout(function(){tw();}, settings.speed);
                    if(text.length === chars){clearTimeout(timeout);}
                };

            el.html("");
            tw();
        });
    };

})(jQuery);

$(function(){
    $('div').typer({speed:25});

    });

动画应该是这样的http://jsfiddle.net/yMYgZ/

(function($) {
    $.fn.typer = function(options) {
        var defaults = {speed: 50},
            settings = $.extend({}, defaults, options);
        return this.each(function(e,options){
            var el = $(this), 
                text = el.html(), 
                chars = 0, 
                timeout = null, 
                tw = function() {
                    el.html(text.substr(0, chars));
                    chars += 1;
                    timeout = setTimeout(function(){tw();}, settings.speed);
                    if(text.length === chars){clearTimeout(timeout);}
                };

            el.html("");
            tw();
        });
    };

})(jQuery);

$(function(){
    $('div').typer({speed:25});
});

如有任何帮助,我们将不胜感激。 谢谢!

最佳答案

显示/隐藏 jquery 方法都有回调。假设您想在带有 id="#somethingThere 的元素淡入之后调用 typer 插件作为示例:

 $('#somethingThere').fadeIn(100, function() {
    $('div').typer({speed:25});
 });

淡入文档示例:http://api.jquery.com/fadeIn/

函数将在淡入发生后执行。

关于jquery - 如何在调用隐藏div时启动jquery动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16041954/

相关文章:

javascript - Bootstrap Modal Form Switch - 一键功能

javascript - 显示时全屏 div 以采用默认窗口滚动条

javascript - 一个文件中有多个函数?

javascript - 在没有堆栈溢出的情况下在javascript中做无限动画的模式

javascript - Div从左上角滑动到右上角的动画

javascript - Velocity.js:第一组对象完成后对第二组对象进行动画处理

jquery 复选框被选中

javascript - Webix Web 皮肤中的样式按钮

javascript - CSS 不适用于 Webpacked 模块

html - 背景图像超出行 < 768 像素