jQuery文本效果,单词一一出现 [英] jQuery text effect where words appear one by one

查看:93
本文介绍了jQuery文本效果,单词一一出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人问我是否可以使用jQuery在HTML中使用文本效果,在此我得到一个字符串,然后例程自动检测单词并将其中的每个单词动画化.

I was asked if I could come up with a text effect in HTML using jQuery where I get a string and then the routine automatically detects the words and animates each word in, one at a time.

就像.

  1. sec进入动画显示:快乐"

  1. sec into the animation shows: "Happy"

sec进入动画显示:"Happy New"

sec into the animation shows:"Happy New"

sec进入动画显示:新年快乐"

sec into the animation shows:"Happy New Year"

sec进入动画显示:"2011年新年快乐"

sec into the animation shows:"Happy New Year 2011"

每个词都应缓慢淡入/动画化",我认为一个以像素为单位的简单滑动窗格会令人满意-但不行.逐字逐句.

each word should "fade/animate" in slowly, I thought a simple sliding pane going right in pixels would be satisfying - but no. Word by word.

对此我可能需要一些想法.我知道一些jQuery和许多Javascript,所以我想我需要一些有关jQuery部分的帮助.

I could need some ideas on this one. I know some jQuery and a lot of Javascript, so I guess I need a bit of help with the jQuery part.

对于单词列表,我只需要分割"(空格)并接受,.!"即可.等是单词的一部分.

For the list of words, I would just split on " " (whitespace) and accept that ",.!" etc are part of a word.

但是我如何为jQuery中的动态数组"设置动画-是在某个地方插入插件,还是我是第一个插件?

But how do I animate this "dynamic array" in jQuery - is there a plugin somewhere or am I the first?

我当时想,项目符号列表也可能是技巧,然后使其像菜单一样水平浮动,然后将该单词作为新项目符号添加,每秒一次.但是,我很高兴看到这里的专家提出了解决方案. :O)

I was thinking that perhaps a bulleted list could be the trick too, then make it float horizontally like a menu and then add the word as a new bullet, once per second. But I am excited to see what the experts in here come up with for solution. :O)

编辑 从标记的答案中,我是这样的:

EDIT From the marked answer, I've this:

    var str = $('div#greeting h1').html(); // grab text
    $('div#welcome h1').html(""); // clear text

    var spans = '<span>' + str.split(" ").join(' </span><span>') + '</span>';
    $(spans).hide().appendTo('div#greeting h1').each(function(i)
    {
        $(this).delay(500 * i).fadeIn();
    });

STRONG标记可以工作,但是文本的某些部分会成组消失.

The STRONG tag works, but somehow parts of the text fades in a group.

尝试一下: 这是一个测试文本.[strong]我们认为这比以往任何时候都要好.并查看问题.

Try this: "here is a test text. [strong]We believe this is better[/strong] than ever." and see the problem.

推荐答案

工作示例: http ://jsfiddle.net/TcdQb/

var str = $('span.ticker').text();

var spans = '<span>' + str.split(/\s+/).join(' </span><span>') + '</span>';

$(spans).hide().appendTo('body').each(function(i) {
    $(this).delay(1000 * i).fadeIn();
});

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