时,函数将执行我有这些代码用于在textarea占位符内进行打字脚本。它工作正常。但我需要执行typeIt函数当我滚动到窗体div时。 “当滚动到
var txt =”滚动到该部分时执行的功能“; var modified_txt =“”;
function humanize() {
return Math.round(Math.random() * (200 - 30)) + 30;
}
//Delete final character in modified string
function deleteCharacter(text) {
//return everything but the last character
text = text.substring(0, text.length - 1);
return text;
}
//Insert character_added at end of text
function addCharacter(text, character_added) {
text = text + character_added;
return text;
}
//typos[char].error is just a self reference, it is not used
var typos = {
}
var timeOut;
var txtLen = txt.length;
var char = 0;
$('textarea').attr('placeholder', '|');
function typeIt() {
modified_txt += txt.charAt(char);
$('textarea').attr('placeholder', modified_txt + '|');
if (char === txtLen) {
$('textarea').attr('placeholder', $('textarea').attr('placeholder').slice(0, -1)); // remove the '|'
return; //Stop the loop once text is completely written.
}
var test = typos[char];
if (test !== undefined) {
setTimeout(function() {
var chunk_one = test.correction(modified_txt);
modified_txt = chunk_one;
char++;
typeIt();
}, humanize());
}
//If no typos are found then move to the next character
else {
setTimeout(function() {
char++;
typeIt();
}, humanize());
}
}
$(function() {
typeIt();
});//end jquery
谢谢萨蒂什。我对jquery没有太多的知识。你能给我一个工作的例子吗? –
@JahidHasan请检查已编辑的答案 –