1

我正在使用一个名为“typed”的 jquery 插件,它一个接一个地输入句子。这很好,但我想知道是否可以暂停代码,直到文本区域在浏览器窗口中可见?

因为我希望人们能够看到输入的第一句话,但目前您会错过第一句话,因为它在页面顶部不可见。

这是我正在处理的页面:http: //jakdesign.webflow.com/

这是html头部的代码:

$(document).ready(function( $ ) {
    $("#hero-text").typed({
        strings: ["First sentence.", "Second sentence."],
        typeSpeed: 0
    });
});

这是插件: https ://rawgithub.com/morr/jquery.appear/master/jquery.appear.js

4

2 回答 2

1

您想在元素可见时初始化 typed ,不是吗?然后尝试这样的事情:

$(document).ready(function( $ ) {
    $("#hero-text").one("appear", function() {
        $(this).typed({
            strings: ["First sentence.", "Second sentence."],
            typeSpeed: 0
        });
    });
});

当然,这需要 jQuery.appear 插件。

于 2013-10-03T09:10:59.227 回答
0

document ready is fired when the DOM has loaded, so all widget attributes are not retrieved completely.

window onload waits for the assets in the page to be completely loaded - so information and attributes of tag are available completely.

So this will work for you:

function typed() {
    $("#hero-text").typed({
        strings: ["First sentence.", "Second sentence."],
        typeSpeed: 0
    });
}

    <body onload="typed()">

OR In script do this

window.onload = function(){
    $("#hero-text").typed({
            strings: ["First sentence.", "Second sentence."],
            typeSpeed: 0
        });
}
于 2013-10-03T08:58:01.810 回答