[英]Change linear-gradient background color when we scroll on a <section>
我有这个网站,我在身体上有一个线性渐变背景,附件是固定的。
我会保留附件,只是想在到达特定部分时更改线性渐变的颜色**。
这个想法是改变这个页面每个部分的颜色。
我能怎么做? 试过 javascript 但无济于事。
body{ Width:100%; height: 100%; text-align: left; background: linear-gradient(163deg, rgba(0,255,255,1) -50%, rgba(255,255,255,1) 27%, rgba(255,255,255,1) 72%, rgba(255,255,0,1) 180%); background-repeat: no-repeat; background-attachment: fixed; }
换栏目时可以用一个javascript function换背景,输入
<head>
<style>
#myDIV {
width: 300px;
height: 300px;
background-color: coral;
color: white;
}
</style>
</head>
<body>
<button onclick="changeBackground()">Change Section</button>
<div id="myDIV">
<h1>Hello</h1>
</div>
<script>
function changeBackground() {
document.getElementById("myDIV").style.background = "linear-gradient(163deg,rgba(0,255,255,1) -50%, rgba(255,255,255,1) 27%, rgba(255,255,255,1) 72%, rgba(255,255,0,1) 180%)";
}
</script>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.