简体   繁体   English

当我们在 a 上滚动时更改线性渐变背景颜色<section></section>

[英]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.

相关问题 如果我有线性渐变,滚动时更改颜色背景 - change color background on scroll if I have linear-gradient 单击时更改线性渐变背景 - Change linear-gradient background on click 我们如何使用 javascript DOM 更改背景图像的线性渐变? - How do we change linear-gradient of background image using javascript DOM? 滚动时根据线性渐变背景设置元素的适当颜色 - Set appropriate color of element base on linear-gradient background when scrolling fullCalendar:将事件背景颜色设置为线性渐变不起作用 - fullCalendar: set event background color to linear-gradient not working 如何使用jQuery更改背景图像属性(线性渐变)? - How to change background-image properties (linear-gradient) with jQuery? 反应背景中的内联样式:线性渐变 - Inline style in react background: linear-gradient 更改值时,HTML5 范围无法使用 javascript 将线性渐变设置为背景。 它会自动在样式中添加一个中心类 - HTML5 range cannot set linear-gradient as background using javascript when change value. It add automatically a center class into the style jQuery语法:-linear-gradient(“颜色”,白色),其中“颜色”为变量 - jQuery Syntax: -linear-gradient(“color”, white) with “color” as variable 画布将线对齐到线性渐变色标 - Canvas aligning lines to linear-gradient color stops
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM