|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 李万金 于 2022-4-28 09:16 编辑
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Scoped CSS Variables and JS</title>
- </head>
- <body>
- <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
- <div class="controls">
- <label for="spacing">Spacing:</label>
- <input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
- <label for="blur">Blur:</label>
- <input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
- <label for="base">Base Color</label>
- <input id="base" type="color" name="base" value="#ffc600">
- </div>
- <img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
- <style>
- :root {
- --base: #ffc600;
- --spacing: 10px;
- --blur: 10px;
- }
- img {
- padding: var(--spacing);
- background: var(--base);
- filter: blur(var(--blur));
- }
- .hl {
- color: var(--base);
- }
- /*
- misc styles, nothing to do with CSS variables
- */
- body {
- text-align: center;
- background: #193549;
- color: white;
- font-family: 'helvetica neue', sans-serif;
- font-weight: 100;
- font-size: 50px;
- }
- .controls {
- margin-bottom: 50px;
- }
- input {
- width: 100px;
- }
- </style>
- <script>
- let inputs = document.querySelectorAll('.controls input');
- function picUpdate(){
- let suffix = this.dataset.sizing || '';
- console.log(this);
- console.log(this.value)
- document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
- }
- inputs.forEach(input => input.addEventListener('change', picUpdate));
- // inputs.forEach(input => input.addEventListener('mousemove', picUpdate));
- </script>
- </body>
- </html>
复制代码 如上传图所示,为什么两个值不同
|
-
-
|