[英]Change linear-gradient background color when we scroll on a <section>
I have this site and I've a linear-gradient background on body which attachment is fixed.我有这个网站,我在身体上有一个线性渐变背景,附件是固定的。
I would to mantain the attachment, just want to change color of linear-gradient **when we reach a specific section.我会保留附件,只是想在到达特定部分时更改线性渐变的颜色**。
The idea is to change color for every section of this page.这个想法是改变这个页面每个部分的颜色。
How can I do?我能怎么做? Tried in javascript but to no avail.
试过 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; }
You can use a javascript function to change the background when changing sections, enter换栏目时可以用一个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.