前提・実現したいこと
:rootにmain-colorでredを設定して、スクロールしてある要素にきた時にmain-colorをblue変えたい。
発生している問題・エラーメッセージ
色が変わらない
Googleの検証で見ましたが、エラーとは書いてありませんでした。
該当のソースコード
HTML
1<meta name="viewport" content="width=device-width,initial-scale=1"> 2<link href="css/reset.css" rel="stylesheet" type="text/css"> 3<link href="css/works.css" rel="stylesheet" type="text/css"> 4<link href="https://fonts.googleapis.com/css?family=Noto+Sans+JP" rel="stylesheet"> 5<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 6<script type="text/javascript" src="./js/site-border.js"></script> 7</head> 8<body> 9<section class="section--01"> 10 <h1>SECTION--01</h1> 11</section> 12<section class="section--02"> 13 <h1>SECTION--02</h1> 14</section> 15<section class="section--03"> 16 <h1>SECTION--03</h1> 17</section> 18</body> 19</html>
css
1@charset "UTF-8"; 2:root { 3 --main-color: red; } 4 5section { 6 height: 150vh; 7 background: var(--main-color); 8 position: relative; 9 -webkit-transition: .8s; 10 -o-transition: .8s; 11 transition: .8s; } 12 13/* 以下関係なし */ 14h1 { 15 font-size: 40px; 16 font-weight: bold; 17 position: absolute; 18 top: 50%; 19 left: 50%; 20 -webkit-transform: translate(-50%, -50%); 21 -ms-transform: translate(-50%, -50%); 22 transform: translate(-50%, -50%); }
js
1var root = document.documentElement; 2$(document).ready(function(){ 3$('.section--01').on('inview', function(event, isInView) { 4 if (isInView) { 5 root.style.setProperty('--main-color', 'red'); 6 } 7}); 8 9$('.section--02').on('inview', function(event, isInView) { 10 if (isInView) { 11 root.style.setProperty('--main-color', '#e04747'); 12 } 13}); 14 15$('.section--03').on('inview', function(event, isInView) { 16 if (isInView) { 17 root.style.setProperty('--main-color', '#035fff'); 18 } 19}); 20});
試したこと
css変数を変化させていくjsを調べて何度も書き換えましたが、ダメでした。
補足情報(FW/ツールのバージョンなど)
sublimetext3,検証はsafariとchromeのみで、どちらも効かず。
ここにより詳細な情報を記載してください。

回答2件
あなたの回答
tips
プレビュー