任何人都可以帮我解释为什么 .substring() 不能使用 setInterval 推出文本吗?
Can anyone help me with why .substring() isn't working with setInterval roll out text?
这个想法是针对文档中带有文本的预定义不可见 P 元素,并使其展开并再次可见(不包括在正文加载事件中使文本不可见的功能) .
我已经评论了不适用于其子字符串方法的代码行。
var tally = 0; //global.
var rollTextOut = function(x){ //make re-usable for all roll-outs.
var anim = setInterval(function(){sequence()}, 50);
function sequence(){
tally++;
if(x===1){
var pHidden1 = document.getElementById("roll1");
pHidden1.style.background="#fff";
pHidden1.style.zIndex="2";
pHidden1.style.visibility="visible";
var text = pHidden1.innerHTML; //targets the p text inside html doc.
pHidden1.innerHTML = text.substring(0, tally); //<why doesn't this work?
}
else if(x===2){
var pHidden2 = document.getElementById("roll2");
pHidden2.style.background="#fff";
pHidden2.style.zIndex="2";
pHidden2.style.visibility="visible";
pHidden2.innerHTML = tally;
}
else if(x===3){
var pHidden3 = document.getElementById("roll3");
pHidden3.style.background="#fff";
pHidden3.style.zIndex="2";
pHidden3.style.visibility="visible";
pHidden3.innerHTML = tally;
}
else{
var pHidden4 = document.getElementById("roll4");
pHidden4.style.background="#fff";
pHidden4.style.zIndex="2";
pHidden4.style.visibility="visible";
pHidden4.innerHTML = tally;
}
if(tally===15){
clearInterval(anim);
tally=0;
}
};
};
非常感谢任何帮助和建议。
您删除了默认文本,因此无法增加下一个字母,因为它不再存在。所以存储对它的引用。
var pHidden1 = document.getElementById("roll1");
if (!pHidden1.myDefaultText) {
pHidden1.myDefaultText = pHidden.textContent || pHidden.innerText;
}
var text = pHidden1.myDefaultText;
pHidden1.innerHTML = text.substring(0, tally);
这个想法是针对文档中带有文本的预定义不可见 P 元素,并使其展开并再次可见(不包括在正文加载事件中使文本不可见的功能) .
我已经评论了不适用于其子字符串方法的代码行。
var tally = 0; //global.
var rollTextOut = function(x){ //make re-usable for all roll-outs.
var anim = setInterval(function(){sequence()}, 50);
function sequence(){
tally++;
if(x===1){
var pHidden1 = document.getElementById("roll1");
pHidden1.style.background="#fff";
pHidden1.style.zIndex="2";
pHidden1.style.visibility="visible";
var text = pHidden1.innerHTML; //targets the p text inside html doc.
pHidden1.innerHTML = text.substring(0, tally); //<why doesn't this work?
}
else if(x===2){
var pHidden2 = document.getElementById("roll2");
pHidden2.style.background="#fff";
pHidden2.style.zIndex="2";
pHidden2.style.visibility="visible";
pHidden2.innerHTML = tally;
}
else if(x===3){
var pHidden3 = document.getElementById("roll3");
pHidden3.style.background="#fff";
pHidden3.style.zIndex="2";
pHidden3.style.visibility="visible";
pHidden3.innerHTML = tally;
}
else{
var pHidden4 = document.getElementById("roll4");
pHidden4.style.background="#fff";
pHidden4.style.zIndex="2";
pHidden4.style.visibility="visible";
pHidden4.innerHTML = tally;
}
if(tally===15){
clearInterval(anim);
tally=0;
}
};
};
非常感谢任何帮助和建议。
您删除了默认文本,因此无法增加下一个字母,因为它不再存在。所以存储对它的引用。
var pHidden1 = document.getElementById("roll1");
if (!pHidden1.myDefaultText) {
pHidden1.myDefaultText = pHidden.textContent || pHidden.innerText;
}
var text = pHidden1.myDefaultText;
pHidden1.innerHTML = text.substring(0, tally);