1 Star 1 Fork 0

ZQY233/原生练习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
背景图鼠标滚动切换.html 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
ZQY233 提交于 2021-10-11 16:40 . 2021-10-11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="carame">
<h1>鼠标滚动</h1>
</div>
</body>
<style>
* {
margin: 0;
padding: 0;
}
body {
margin-bottom: 20000px;
}
h1 {
position: absolute;
left: 100px;
top: 100px;
font-size: 40px;
color: white;
}
.carame {
position: fixed;
width: 100vw;
height: 100vh;
background-image:
url('https://wwwstatic.vivo.com.cn/vivoportal/files/resource/product/1603437675413/images/camera_1.jpg');
background-color: black;
}
</style>
<script>
let i = 1
window.onscroll = () => {
if (document.documentElement.scrollTop % 2 == 0) {
i++
}
if (i > 49) {
i = 0
}
var img = new Image();
img.src =
`https://wwwstatic.vivo.com.cn/vivoportal/files/resource/product/1603437675413/images/camera_${i}.jpg`;
img.onload = () => {
document.querySelector('.carame').style.backgroundImage =
`url(https://wwwstatic.vivo.com.cn/vivoportal/files/resource/product/1603437675413/images/camera_${i}.jpg)`
}
}
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zqylzcwcxy/native-practice.git
[email protected]:zqylzcwcxy/native-practice.git
zqylzcwcxy
native-practice
原生练习
master

搜索帮助