这是我的 image1 课程。单击此按钮时,我想更改背景图像。
<li class="sidebar-element">
<div class="image1">
<i class="fa fa-home" aria-hidden="true"></i>
<span>Image 1</span>
<hr>
<hr id="second">
</div>
</li>
这是同一文件中的 Javascript 代码。
<script type="text/javascript">
var image1 = document.querySelectorAll(".image1");
image1.addEventListener("click", function(){
document.body.style.backgroundimage = "url(https://images.unsplash.com/photo-1582392487150-b0bc00f92e28?ixlib=rb- 1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60)";
});
我有一个在我的 css 文件中定义的原始背景图像。
body{
font-family: 'Open Sans', sans-serif;
font-size: 18px;
font-weight: 300;
color: white;
overflow-x: hidden;
height: 100%;
background: #222222;
background-image: url("https://images.unsplash.com/photo-1582392487150-b0bc00f92e28?ixlib=rb- 1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60");
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
大话西游666
守着星空守着你
相关分类