最近我一直在学习一些 javascript 来改进我的页面。
我尝试做一个简单的练习,每 5 秒更改一个元素,但是当我尝试使用 css 添加淡入淡出动画并且仅适用于第一次时,此时我真的不知道我的 javascript 是否不是以正确的方式编写或者它与我的css有关。
有更多知识和经验的人能给我一些建议吗?
好的,所以基本上问题是我不能让动画像句子一样重复,你可以在这里查看:
//Calling the element.
var $slogan = document.getElementById("slogan");
// Setting an array with several strings.
var sloganArray = ["This sentence will change every 5 seconds!", "See? I'm changing!", "Knock Knock.", "Who's there?", "Heck I don't know!"];
//Setting variable to control the index.
var sloganIndex = 0;
/* This function (only when called) replaces the text of the element called before with text contained on the strings of the array, …
Run Code Online (Sandbox Code Playgroud)所以自从我开始学习JavaScript的我一直在读这本书叫学习JavaScript由蒂姆·赖特。
在这本书中,我找到了关于如何移动和定位DOM树中元素的章节,其中之一是利用以兄弟姐妹为目标的属性,而在本书中进行练习时,我根本无法使以下语句起作用:
<ul id="nav">
<li><a href="/" id="home">Home</a></li>
<li><a href="/about" id="about">About Us</a></li>
<li><a href="/contact" id="contact">Contact Us</a></li>
</ul>
<script>
//Should add "next" class attribute to the "Contact Us" li tag.
document.getElementById("about").parentNode.nextSibling.setAttribute("class", "next");
</script>
Run Code Online (Sandbox Code Playgroud)
快速浏览此代码后,我想知道您中是否有经验更丰富的开发人员可以帮助我,并向我解释为什么此方法无法正常工作。我感到困惑是因为我不知道我做错了什么还是关于这些属性的文章拼写错误。
无论如何,感谢您的时间和提前的帮助!
干杯!
阿尔梅达
虽然我正在编写一些CSS,但在使用之前我从未遇到过这种情况,我:nth-child(n)
怀疑实际发生了什么.
当我使用伪类时,我在选择器之间没有空格的情况下编写它们,如下所示:
div#wrap:hover {
border-bottom: 2px solid orange;
}
/* OR */
div#wrap:nth-child(4) {
border-bottom: 2px solid orange;
}
Run Code Online (Sandbox Code Playgroud)
但它没有按照我的预期工作,所以我尝试在选择器和伪类之间插入一个空格.令人惊讶的是,它有效:
div#wrap :nth-child(4) {
border-bottom: 2px solid orange;
}
Run Code Online (Sandbox Code Playgroud)
发生了什么使这项工作?
div#wrap :nth-child(4) {
border-bottom: 2px solid orange;
}
Run Code Online (Sandbox Code Playgroud)
<div id="wrap">
<h1>Heading 1</h1>
<p>This is a test!</p>
<h2>Creating content</h2>
<p>The next paragraph uses the <strong>.html</strong> method to create a new element.</p>
</div>
Run Code Online (Sandbox Code Playgroud)