3秒後+可視範囲でClassを付与した場合、そのままの動きとなりましたが、
この状態+3秒待たずにスクロール可視状態になったらClassを付与させたい。
また、box発火後、img1→img2→img3と順番にclassを付与させてみましたが、なんか違う...ような気がします。
頑張ってみましたが、うまいやり方はありますでしょうか?
何卒よろしくお願いいたしますm(__)m
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js"></script> <style> #loading { width: 100vw; height: 100vh; transition: all 1s; background-color: #000; position: fixed; top: 0; left: 0; z-index: 9999; } .spinner { width: 960px; height: 448px; margin: 0 auto; border-radius: 100%; position: absolute; top: 50%; left: 50%; transform: translateY(-50%) translateX(-50%); -webkit- transform: translateY(-50%) translateX(-50%); } @keyframes sk-scaleout { 0% { transform: scale(0); } 100% { transform: scale(1.0); opacity: 0; } } .loaded { opacity: 0; visibility: hidden; } .isMove { display: none;} .isMove.mask2 { display: block;} .container { display: flex; flex-wrap: wrap; justify-content: space-between; width: 100%; max-width: 700px; height: auto; margin: 0 auto; padding: 40px 0; } .box { width: 100%; height: 200px; margin: 0 0 2% 0; overflow: hidden; } .boxInner { width: inherit; height: inherit; line-height: 200px; font-size: 1.5em; text-align: center; color: #555; opacity: 0; } .isPlay { animation-name: play; animation-duration: .5s; animation-fill-mode: forwards; animation-timing-function: cubic-bezier(.8,0,.5,1); position: relative; opacity: 1 !important; } .isPlay:before { animation-name: maskOut; animation-duration: .5s; animation-delay: .5s; animation-fill-mode: forwards; animation-timing-function: cubic-bezier(.8,0,.5,1); content: ''; position: absolute; top: 0; left: 0; z-index: 1; width: 100%; height: 100%; background: #000; } @keyframes play { from { transform: translateX(-100%); } to { transform: translateX(0); } } @keyframes maskOut { from { transform: translateX(0); } to { transform: translateX(100%); } } .Vd.isPlay { animation-name: play2; animation-duration: .5s; animation-fill-mode: forwards; animation-timing-function: cubic-bezier(.8,0,.5,1); position: relative; opacity: 1; } .Vd.isPlay:before { animation-name: maskOut2; animation-duration: .5s; animation-delay: .5s; animation-fill-mode: forwards; animation-timing-function: cubic-bezier(.8,0,.5,1); content: ''; position: absolute; top: 0; left: 0; z-index: 1; width: 100%; height: 100%; background-: #000; } @keyframes play2 { from { transform: translateY(-100%); } to { transform: translateY(0); } } @keyframes maskOut2 { from { transform: translateY(0); } to { transform: translateY(100%); } } .conInr .box { width: max-content; height: auto; margin: 0 0 0 0; overflow: hidden; } .conInr .box img { width: 100%; } .conInr, .conInr .boxInner { position: relative; padding-bottom: 60%; width: 100%;} .img1, .img2, .img3, .img4, .img5 { position: absolute !important; overflow: hidden; opacity: 0;} .img1.isPlay { width: 90%; left: 0; right: 0; margin: 0 auto; opacity: 1; } .img2.isPlay { width: 50%; right: 2%; top: 55%; } .img3.isPlay { width: 40%; left: 2%; top: 55%; } .img4.isPlay { width: 100%; } .img5.isPlay { width: 30%; left: 15%; top: 30%; } .boxImg4 { position: absolute !important; width: 20% !important; right: 2%; top: 5%; overflow: hidden !important; height: 0; padding-bottom: 14%;} </style> </head> <body> <div class="wrapper"> <div id="loading"> <div class="spinner"> <svg viewBox="0 0 0 1" class="mask" id="movie" > <mask id="clip"> <g id="mask"></g> </mask> <image xlink:href="hoge.svg" width="100%" height="100%" mask="url(#clip)"></image> </svg> </div> </div> <main> <section> <div class="container"> <div class="box"> <div class="boxInner">Lorem Ipsum</div> <div class="boxInner">Lorem Ipsum</div> <div class="boxInner">Lorem Ipsum</div> </div> <div class="box"> <div class="boxInner">Lorem Ipsum</div> </div> <div class="box"> <div class="boxInner">Lorem Ipsum</div> </div> <div class="box"> <div class="boxInner">Lorem Ipsum</div> </div> </div> </section> <section> <svg viewBox="0 0 0 2" class="isMovie" id="move" > <mask id="clipMask"> <g id="mask"></g> </mask> <image xlink:href="huga.svg" width="100%" height="100%" mask="url(#clipMask)"></image> </svg> <div class=" "> <div class="conInr"> <div class="box"> <div class="img1"><img src="http://into-the-program.com/demo/images/sample001.jpg" alt=""></div> </div> <div class="box"> <div class="img2"><img src="http://into-the-program.com/demo/images/sample002.jpg" alt=""></div> </div> <div class="box"> <div class="Vd img3"><img src="http://into-the-program.com/demo/images/sample003.jpg" alt=""></div> </div> <div class="box"> <div class="Vd img4 boxImg4"><img src="http://into-the-program.com/demo/images/sample004.jpg" alt=""></div> </div> <div class="box"> <div class="img5"><img src="http://into-the-program.com/demo/images/sample005.jpg" alt=""></div> </div> </div> </div> </section> </main> </div> <script src="https://cdn.jsdelivr.net/npm/vivus@latest/dist/vivus.min.js"></script> <script> window.onload = function () { setTimeout(() => { const spinner = document.getElementById('loading'); spinner.classList.add('loaded'); boxShow(); MovieShow(); box1Show(); box2Show(); box3Show(); box4Show(); box5Show(); $(window).on('scroll', function () { boxShow(); }); $(window).on('scroll', function () { MovieShow(); }); $(window).on('scroll', function () { box1Show(); }); $(window).on('scroll', function () { box2Show(); }); $(window).on('scroll', function () { box3Show(); }); $(window).on('scroll', function () { box4Show(); }); $(window).on('scroll', function () { box5Show(); }); }, 3000); } function boxShow() { var elem = $('.boxInner'); elem.each(function () { var isPlay = 'isPlay'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).addClass(isPlay); } }); } function MovieShow() { var elem = $('.isMovie'); elem.each(function () { var isMovie = 'isMovie'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).attr("class", "mask2"); new Vivus('move', { type: 'oneByOne', start: 'inViewport', duration: 180, forceRender: false, animTimingFunction: Vivus.LINEAR, }); } }); } function box1Show() { setTimeout(() => { var elem = $('.img1'); elem.each(function () { var isPlay = 'isPlay'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).addClass(isPlay); } }); }, 2800); } function box2Show() { setTimeout(() => { var elem = $('.img2'); elem.each(function () { var isPlay = 'isPlay'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).addClass(isPlay); } }); }, 3000); } function box3Show() { setTimeout(() => { var elem = $('.img3'); elem.each(function () { var isPlay = 'isPlay'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).addClass(isPlay); } }); }, 3200); } function box4Show() { setTimeout(() => { var elem = $('.img4'); elem.each(function () { var isPlay = 'isPlay'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).addClass(isPlay); } }); }, 3400); } function box5Show() { setTimeout(() => { var elem = $('.img5'); elem.each(function () { var isPlay = 'isPlay'; var elemOffset = $(this).offset().top; var scrollPos = $(window).scrollTop(); var wh = $(window).height(); if(scrollPos > elemOffset - wh + (wh / 10)){ $(this).addClass(isPlay); } }); }, 3600); } new Vivus('movie', { type: 'oneByOne', start: 'inViewport', duration: 180, forceRender: false, animTimingFunction: Vivus.LINEAR, }); </script> </body> </html>
回答1件
あなたの回答
tips
プレビュー