javascript - Javascript在特定时间更改文本阴影方向
问题描述
我正在尝试使用 javascript 在晚上 9 点到 10 点之间更改文本阴影的方向。
尝试了许多更改,但不确定我哪里出错了,这是我的代码的基础知识..
<head>
<style>
body {
text-shadow: 12px 12px 8px #000000;
}
</style>
<script>
var currentTime = new Date().getHours();
if (21 <= currentTime && currentTime < 22)
{
document.getElementById('body').text.style.textShadow = "-12px 12px 8px
#000000";
}
</script>
</head>
.. 没有包含正文,但我的文本在 <div class="..." > 和 <a href="..." > 中,如果这有帮助?
所以通常文本阴影应该在右边,晚上 9 点到 10 点应该在左边?
谢谢!
解决方案
根据评论,我认为这是错误的:
document.getElementById('body').text
一个示例片段来澄清:
document.addEventListener('DOMContentLoaded', function(e) {
document.querySelector('button').addEventListener('click', function(e) {
document.querySelectorAll('div, a').forEach(function(ele) {
ele.style.textShadow = "-12px 12px 8px #000000";
});
})
});
body {
text-shadow: 12px 12px 8px #000000;
}
<div>
this is a text iside a div......
</div>
<a href="">this is a text inside an anchor......</a>
<br/>
<br/>
<button type="button">Click Me</button>
推荐阅读
- javascript - 独立运行的函数内的 Javascript 警报
- visual-studio - 除非连接了 VPN,否则不会安装具有多个源(两个 corp 和两个 Microsoft)的 nuget 包
- reactjs - 你可以在反应中做哪些类型的测试?
- javascript - 如何在反应中显示来自远程 .csv 文件的数据?
- angular - 在Angular中全局阻止ALT键
- android - 我正在尝试让一个在旧版 Android 手机上运行的应用程序在 Galaxy S20 FE 5G 上运行。来自 adb logcat 的日志说“libiconv.so”未找到
- html - 如何使用ngFor Angular从服务器获取json数组中的随机对象
- r - C 如何干扰并行 R 并且可以解决它吗?
- android - 谁能看到为什么我的 Spinner 中没有保存任何输入?
- javascript - 从 jQuery 编辑器获取价值到 PHP