gpt4 book ai didi

javascript - 设置超时后jquery运行函数

转载 作者:行者123 更新时间:2023-11-29 18:25:48 25 4
gpt4 key购买 nike

我有一个运行良好的动画,但现在我试图通过淡出文本然后运行另一个函数来反转此动画。加载此页面后,将运行以下...

 $(document).ready(function () {

dream();
setTimeout(runul(), 8000, function() {showVideo()});

});

dream 函数在 body 背景上创建气泡。

 function dream() {
//calculating random color of dream
if (animation_stopped) return;
var color = 'rgb(' + Math.floor(Math.random() * 255) + ',' + Math.floor(Math.random() * 255) + ',' + Math.floor(Math.random() * 255) + ')';

//calculating random X position
var x = Math.floor(Math.random() * $(window).width());

//calculating random Y position
var y = Math.floor(Math.random() * $(window).height());

//creating the dream and hide
drawingpix = $('<span>').attr({ class: 'drawingpix' }).hide();

//appending it to body
$(document.body).append(drawingpix);

//styling dream.. filling colors.. positioning.. showing.. growing..fading
drawingpix.css({
'background-color': color,
'border-radius': '100px',
'-moz-border-radius': '100px',
'-webkit-border-radius': '100px',
top: y - 14, //offsets
left: x - 14 //offsets
}).show().animate({
height: '500px',
width: '500px',
'border-radius': '500px',
'-moz-border-radius': '500px',
'-webkit-border-radius': '500px',
opacity: 0.1,
top: y - 250, //offsets
left: x - 250
}, 3000).fadeOut(2000);

//Every dream's end starts a new dream
window.setTimeout('dream()', 200);
}

当 dream 函数运行时,我运行 runul() 函数,它开始输入文本。

 function runul() {
jQuery("#ticker").ticker({
cursorList: " ",
rate: 50,
delay: 18000
}).trigger("play").trigger("stop");

// Trigger events
jQuery(".stop").click(function () {
jQuery("#ticker").trigger("stop");
return false;
});

jQuery(".play").click(function () {
jQuery("#ticker").trigger("play");
return false;
});

}

当 runul() 动画完成后,我想运行 showVideo 函数。我希望此函数淡出键入的文本,然后淡入包裹在 div 中的 iframe。

 function showVideo() {
$('#divFade').fadeOut(3000);
animation_stopped = true;
$(typetext).css('color', 'black');
$("body").animate({ backgroundColor: "#ffffff" }, 3000);
$('#divVideos').fadeIn('slow');
// Animation complete.
$("#iVideos").prop('src', 'Videos/Quick Start Intro_player.html');
return false;
};

如何让 showVideo 在 runul() 完成后运行?

非常感谢您的帮助

最佳答案

您应该将“showVideo”作为回调函数传递:

setTimeout( function() {runul(showVideo)},8000);

function runul(callback) {
jQuery("#ticker").ticker({
cursorList: " ",
rate: 50,
delay: 18000
}).trigger("play").trigger("stop");

// Trigger events
jQuery(".stop").click(function () {
jQuery("#ticker").trigger("stop");
return false;
});

jQuery(".play").click(function () {
jQuery("#ticker").trigger("play");
return false;
});

callback();

}

您还可以使用 jquery defferred具体来说,when功能

关于javascript - 设置超时后jquery运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13363622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com