[英]Change from using fontawesome icon to an image
<script>
var today = new Date();
var hourNow = today.getHours();
var greeting;
var icon;
if (hourNow < 12) {
greeting = "Good Morning";
icon = "coffee";
} else if (hourNow < 20) {
greeting = "Good afternoon!";
icon = "sun";
} else if (hourNow < 24) {
greeting = "Good evening";
icon = "moon";
} else {
greeting = "Welcome";
}
document.getElementById("col-1").innerHTML = "<h3>" + greeting + " </h1>";
document.getElementById("icon").innerHTML =
'<i class="fas fa-' + icon + '" aria-hidden="true"></i>';
</script>
This is the code I am using above - the icon name is added after the "fas fa-" How can I not use font awesome and just have an image appear for the different times of the day instead?这是我在上面使用的代码 - 图标名称添加在“fas fa-”之后我怎么能不使用很棒的字体而只在一天中的不同时间显示图像? Thanks
谢谢
Replace the URLs with images of your choice:用您选择的图像替换 URL:
if (hourNow < 12) {
greeting = "Good Morning";
icon = "https://picsum.photos/50";
} else if (hourNow < 20) {
greeting = "Good afternoon!";
icon = "https://picsum.photos/50";
} else if (hourNow < 24) {
greeting = "Good evening";
icon = "https://picsum.photos/50";
} else {
greeting = "Welcome";
}
document.getElementById("col-1").innerHTML = "<h3>" + greeting + " </h3>";
document.getElementById("icon").innerHTML = `<img src=${icon} alt="">`;
Also, fix the closing tag of your heading.另外,修复标题的结束标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.