例如,如果我有一个变量:
const template = `line 1
line 2
line 3`;
Run Code Online (Sandbox Code Playgroud)
我想console.log(template)打印:
第 1 行\n第 2 行\n第 3 行
我想在滚动期间激活时更改background-color导航栏的position: sticky。
background-color当滚动到达时,我设法更改了导航栏的 ,但我想为其设置动画以使这种变化更加渐进。
这是我尝试过的:
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("menu_navbar");
var rect = navbar.getBoundingClientRect();
function myFunction() {
if (window.pageYOffset >= rect.top) {
$( "#menu_navbar" ).animate({
"background-color": "rgba(255, 229, 57, 0.8)"
}, 1000);
}
else {
navbar.style.backgroundColor = 'transparent';
}
}
Run Code Online (Sandbox Code Playgroud) 我有 HTML:
<div class="dropdown">
<button class="dropbtn">Game Design</button>
<div class="dropdown-content">
<a id="GameIdea" href="GameIdea.html">Link 1</a>
<a id="GameMechanics" href="GameMechanics.html">Link 2</a>
<a id="GameCharacters" href="GameCharacters.html">Link 3</a>
<a id="Inspiration" href="Inspiration.html">Link 3</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和 JavaScript:
var anchor = document.getElementById(pathShort); //e.g. pathShort == GameIdea
var anchorParent = anchor.parentNode;
var button = anchorParent.previousSibling;
button.classList.add("active");
Run Code Online (Sandbox Code Playgroud)
问题是这样的 - 我不想要锚元素:document.getElementById(pathShort);
我想要按钮元素,因此正如您所看到的,我anchor.parentNode;用来获取div锚点所在的 ,然后anchorParent.previousSibling;获取 , 旁边的元素div,而不是之后。
在我看来,我认为这会起作用,但在控制台中我得到了错误Cannot read property 'add' of undefined,因此变量button必须有效null或empty,这意味着我在“添加”调用之前的 DOM 遍历方法不起作用。
我有一个div带有一些文本的文件以及一个链接。
<a href="mypage.html">
<div>
Text goes here ...
</div>
</a>
Run Code Online (Sandbox Code Playgroud)
但是,我只希望链接在特定页面宽度下工作,即小于或等于625px。我知道下面的代码是胡说八道,但是它说明了我正在寻找的东西:
a {
follow-link: no;
}
@media (max-width: 625px){
a {
follow-link: yes;
}
}
Run Code Online (Sandbox Code Playgroud)
使用javascript的解决方案对我也很好。
谢谢你的帮助!
如果 a 中只有三段div,结果应该是最后一段是红色的。
last-of-type但是,如果我的中只有一个段落,我该如何忽略结果呢div?
CSS:
p:last-of-type {
background: #ff0000;
}
Run Code Online (Sandbox Code Playgroud) 我在尝试全局安装 Laravel 时出错。
当我写composer global require laravel/installer
我得到这个错误:
Problem 1
- Installation request for laravel/installer ^3.1 -> satisfiable by laravel/installer[v3.1.0].
- Conclusion: remove symfony/console v3.4.38
- Conclusion: don't install symfony/console v3.4.38
- laravel/installer v3.1.0 requires symfony/console ^4.0|^5.0 -> satisfiable by symfony/console[v4.0.0, v4.0.1, v4.0.10, v4.0.11, v4.0.12, v4.0.13, v4.0.14, v4.0.15, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0, v4.2.1, v4.2.10, v4.2.11, v4.2.12, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, …Run Code Online (Sandbox Code Playgroud)