简体   繁体   English

在HTML5 / jQuery / css3中将单词动画(显示和消失)到毫秒

[英]Animating words (appear and disappear) to milliseconds in HTML5 / jQuery / css3

I'm a newbie with jQuery and @keyframes with css3, so I turn to you for advices. 我是jQuery的新手,而css3是@keyframes,所以我向您寻求建议。 I need to create a 30 seconds animation of words and non-words that appear and disappear very quickly at precisely set delays in milliseconds. 我需要创建一个30秒的动画,该动画包含以精确设置的毫秒为单位的快速出现和消失的单词和非单词。 See demo in flash here: http://www.elaborer.uqam.ca/test.html 在此处查看Flash演示: http//www.elaborer.uqam.ca/test.html

Is it possible to do the same thing in HTML5 using jQuery or css3 (or any other way)? 是否可以使用jQuery或css3(或任何其他方式)在HTML5中执行相同的操作?

In jQuery, the functions FadeIn and FadeOut seem like a potential solution, but I have no idea how I could iterate hundreds words through these: 在jQuery中,FadeIn和FadeOut函数似乎是一个潜在的解决方案,但是我不知道如何遍历这些单词成百上千个单词:

<div id="test">Attention!</div>

$(function() {
$('#test').fadeOut(100, function() {
    $(this).text('Bunny').fadeIn(100);
});
 $('#test').fadeOut(100, function() {
    $(this).text('Turtle').fadeIn(100);
});

Another idea I had was to use Bunny Turtle tags on top of each other and animate their opacity using @keyframes, but it seems very inconvenient to use for more than a hundred words. 我的另一个想法是在彼此之间使用Bunny Turtle标签,并使用@keyframes为它们的不透明度设置动画,但是使用一百多个单词似乎非常不便。

Another requirement is that the solution works on Ipad Safari. 另一个要求是该解决方案可以在Ipad Safari上运行。

Any thoughts? 有什么想法吗?

EDIT 编辑

I approximated the most what I had using this. 我最近似使用此工具。 Probably not the most elegant solution though. 可能不是最优雅的解决方案。 If anyone has ideas to make it better, I'd be very interested. 如果有人有更好的想法,我会很感兴趣。

<span id="foo"></span>

var arr = ["turtle", "bunny", "rabbit", "chicken", "moose", "penguin", "ant", "buffalo", "mouse", "deer", "phoque"];
var narr = ['dsfadsf', 'fasdfsaf', 'dsfasd', 'dsfsaafds', 'fdafaf', 'wwwww', 'yetszfs'];
var key = ['stack', 'over', 'flow', 'jquery', 'html5', 'javascript'];

$("#foo").fadeIn(1).delay(200).html(narr[0]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(50).html(key[0]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(200).html(narr[1]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(400).html(arr[0]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(50).html(narr[2]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(200).html(narr[1]).fadeOut(1, function(){

$("#foo").fadeIn(1).delay(50).html(key[1]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(200).html(narr[2]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(400).html(arr[1]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(50).html(narr[3]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(200).html(narr[2]).fadeOut(1, function(){

$("#foo").fadeIn(1).delay(50).html(key[2]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(200).html(narr[3]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(400).html(arr[2]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(50).html(narr[4]).fadeOut(1,function(){
$("#foo").fadeIn(1).delay(200).html(narr[3]).fadeOut(1, function(){

//etc.

});}); }); }); }); });      
}); }); }); }); });
}); }); }); }); });

I did something similar quite recently where i created a slideshow of sorts for a series of sentences. 我最近做了类似的事情,在其中我创建了一系列句子的幻灯片放映。 jquery is a easy simple way of doing that. jQuery是一种简单易行的方法。 you can use the setInterval function to iterate over a series of words stored in an array for example. 例如,您可以使用setInterval函数来迭代存储在数组中的一系列单词。 You can chain fadeIn and fadeOut to get a nice transition effect if you want. 如果需要,可以链接fadeIn和fadeOut以获得不错的过渡效果。

i=0
setInterval(function() {
    if (i == messages.length)
     { some action }
    else
    {
        $('#message').fadeIn(*time*).delay(*time*).html(words[i]).fadeOut(*time*);
        i++;  //counter, set to 0 initially
    }
}, x * 1000); //repeats actions after every x seconds.

One thing to note is that if the sum of all the time in the else block, should be equal to or less than the time x for setinterval for smooth and correct transition effects. 要注意的一件事是,如果else块中所有时间的总和应等于或小于setinterval的时间x,以实现平稳正确的过渡效果。

I hope this helps point you in the right direction. 我希望这可以帮助您指出正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM