- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这个 JavaScript 函数在 div 之间切换:
function show(shown, hidden) {
document.getElementById(shown).style.display='block';
document.getElementById(hidden).style.display='none';
return false;
}
我尝试了一点文本动画,但问题是文本动画应该在我从第 1 页到达第 2 页时开始。但是,当我加载页面时,来自 javascript 的文本动画就会运行,我是仍在第 1 页。
这是完整的 html 页面:
<!DOCTYPE html>
<html>
<head>
<script>
function show(shown, hidden) {
document.getElementById(shown).style.display='block';
document.getElementById(hidden).style.display='none';
return false;
}
</script>
</head>
<body>
<div id="Page1">
Content of page 1
<a href="#" onclick="return show('Page2','Page1');">Show page 2</a>
</div>
<div id="Page2" style="display:none">
<div id="typedtext"></div>
<script>
var aText = new Array(
"hey man",
"how are you",
"how is it going"
);
var iSpeed = 100; // time delay of print out
var iIndex = 0; // start printing array at this posision
var iArrLength = aText[0].length; // the length of the text array
var iScrollAt = 20; // start scrolling up at this many lines
var iTextPos = 0; // initialise text position
var sContents = ''; // initialise contents variable
var iRow; // initialise current row
function typewriter()
{
sContents = ' ';
iRow = Math.max(0, iIndex-iScrollAt);
var destination = document.getElementById("typedtext");
while ( iRow < iIndex ) {
sContents += aText[iRow++] + '<br />';
}
destination.innerHTML = sContents + aText[iIndex].substring(0, iTextPos) + "_";
if ( iTextPos++ == iArrLength ) {
iTextPos = 0;
iIndex++;
if ( iIndex != aText.length ) {
iArrLength = aText[iIndex].length;
setTimeout("typewriter()", 500);
}
} else {
setTimeout("typewriter()", iSpeed);
}
}
window.onload = typewriter();
</script>
<a href="#" onclick="return show('Page1','Page2');">Show page 1</a>
</div>
</body>
</html>
我怎样才能让javascript函数在我点击进入第2页后显示第2页div后才开始运行?
最佳答案
如果要显示的元素的 ID 为 "Page2"
,您应该只执行 typewriter
函数。
function show(shown, hidden) {
document.getElementById(shown).style.display='block';
document.getElementById(hidden).style.display='none';
if(shown === 'Page2'){
typewriter();
}
return false;
}
实例:
<!DOCTYPE html>
<html>
<head>
<script>
function show(shown, hidden) {
document.getElementById(shown).style.display = 'block';
document.getElementById(hidden).style.display = 'none';
if (shown === 'Page2') {
typewriter();
}
return false;
}
</script>
</head>
<body>
<div id="Page1">
Content of page 1
<a href="#" onclick="return show('Page2','Page1');">Show page 2</a>
</div>
<div id="Page2" style="display:none">
<div id="typedtext"></div>
<script>
var aText = new Array(
"hey man",
"how are you",
"how is it going"
);
var iSpeed = 100; // time delay of print out
var iIndex = 0; // start printing array at this posision
var iArrLength = aText[0].length; // the length of the text array
var iScrollAt = 20; // start scrolling up at this many lines
var iTextPos = 0; // initialise text position
var sContents = ''; // initialise contents variable
var iRow; // initialise current row
function typewriter() {
sContents = ' ';
iRow = Math.max(0, iIndex - iScrollAt);
var destination = document.getElementById("typedtext");
while (iRow < iIndex) {
sContents += aText[iRow++] + '<br />';
}
destination.innerHTML = sContents + aText[iIndex].substring(0, iTextPos) + "_";
if (iTextPos++ == iArrLength) {
iTextPos = 0;
iIndex++;
if (iIndex != aText.length) {
iArrLength = aText[iIndex].length;
setTimeout("typewriter()", 500);
}
} else {
setTimeout("typewriter()", iSpeed);
}
}
</script>
<a href="#" onclick="return show('Page1','Page2');">Show page 1</a>
</div>
</body>
</html>
关于javascript - div为 'shown'后才运行Javascript,显示:block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63420864/
我正在尝试在 Windows 上测试我的 JavaFX 桌面应用程序并为其导出一个 jar 文件。我的Eclipse IDE版本:2019-03(4.11.0) Java Class Controll
×
当值显示为父列总数的百分比时,有没有办法让数据透视表自动计算 2 列之间的差异? 现在我需要手动操作,但表格是动态的,竞争对手的数量可能会有所不同。功能似乎很简单,但在谷歌搜索等后找不到它......
我通过组合 JTree 和 JTable 创建了自定义表结构。 它看起来像这样: 可以对任何元素添加叶子。 但是当我尝试将节点添加到已有子节点的行时,链接未显示,新添加的行也未显示。 这是将新行添加到
我正在从 shell 运行一些 MySQL 查询。在查询结果的末尾,MySQL 会打印结果中的总行数和持续时间。 mysql>select * from mytable; [Query result
我正在使用一些 jquery 来让 Bootstrap 4 导航栏在向下滚动超过某个点时淡入,方法是添加和删除特定类。但是,如果我重新加载已经向下滚动的页面,我的代码将不会显示导航栏,并且当向上滚动时
问题是,搜索后没有显示结果.. 搜索是使用 textform 完成的。表单可以基于多个文本表单进行搜索,我的代码有什么问题吗?还是 php 的新手 $sql = " SELECT jobs
我有一个简单的布局,其中包含一个 Column 和几个 child 。其中一些是包含子项的行。我在 Column 的子项之间添加了 Dividers,在 Rows 的子项之间添加了 VerticalD
如何断言未显示对话框? 目前我有一个测试,它检查对话框中是否不存在文本 onView(withText("Mobile connection")).inRoot(isDialog()).check(d
当我第一次尝试显示模态时出现问题。显示了模态框,但当我拖动模态框或单击关闭按钮时,会触发 shown 事件(我看到警报)。我将 Bootstrap 2.3.2 与 Firefox 26.0 一起使用。
我的 gsp(Grails 项目)中有一个输入标签字段,我想在字段为空时使用占位符显示一些文本: /> 当我创建一个新对象时,value不是空的,但它有一个空格,所以不显示占位符。 如何更改这种行为以
我需要从某些 console.log() 获取信息,但是 Safari 只是用“x(number) console messages are not shown”来问候我。相反,所以我卡住了,对着屏幕
我已经更新了 og:description 标签以及 this 的其他标签页。调试器在 debugger 中显示了这一点。但是当我在 Facebook 上分享它时也不会在预览中显示它。可能出了什么问题
我在使用 Bootstrap 模式时遇到一些问题。第一次调用我的模态时,它位于左侧约 20px 处,但之后它根据 .position() 正确定位 这是我的代码: HTML:
我正在使用 SqlQuery() 从 DbContext 调用存储过程。当我运行查询时,出现错误 Procedure or function 'p_Insert_Phones' expects par
我有一个 ListView,其中每个项目都可以横向滑动,以便另一个 View 滑入并取代它。我已将每个列表行实现为水平 RelativeLayout 中的两个 View 。其中一个 View 最初位于
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
在我当前的 Eclipse 配置中,src 文件夹在所有地方的显示方式都不一样! 正如您在下面的屏幕截图中看到的,com.WazaBe.BePlanes 显示为一个包,tof.cv.mpp 显示为文件
1/如果这个已经在前台运行我的应用程序,我不想通知用户, 是否可以在创建通知之前检查我的应用程序是否不在前面? 2/如果应用程序在后台,是否可以将最后一个状态放在前面? 我知道 Os 可以销毁一些 A
当我在 pyplot 中制作子图时,光标的位置没有正确显示,如下图所示(光标位于右上角的某个位置(所有其他子图都经历过相同的行为),但是当我截屏时,光标不在那里(我使用的是 Win10): [] 之间
我是一名优秀的程序员,十分优秀!