2017-11-10 18 views
0

저는 JavaScript가별로 좋지 않습니다.하지만이 애니메이션을 수행하여 작업을 완료해야합니다.TimelineMax 및 ScrollMagic 플러그인을 사용하여이 애니메이션을 어떻게 실현할 수 있습니까?

on this website과 같은 애니메이션을 구현해야합니다. blue block 칫솔과 휴대기로 "세상을 만드는 이유"를 확인하십시오. 이를 구현하기 위해 저자는 TimelineMaxscrollMagic이라는 플러그인을 사용합니다.

스크롤을 사용하여 블록을 수정할 수 있었지만 다음에 무엇을해야할지 모르겠다. #slider 블록에 대한 스크롤은 어떻게합니까?

Codepan에 대한 링크.

$(document).ready(function() { 
 

 
// scrollmagic 
 

 
(function($) { 
 

 
    var wh = window.innerHeight, 
 
     $zone = $('#owlZone'), 
 
     $slider = $('#slider'), 
 
     $itemOne = $('#itemOne'), 
 
     $itemTwo = $('#itemTwo'), 
 
     $itemThree = $('#itemThree'); 
 
    var ScreenHeight = $(window).height(); 
 
    
 
    var ctrl = new ScrollMagic.Controller({ 
 
     globalSceneOptions: { 
 
      triggerHook: 0, 
 
      tweenChanges: true, 
 
      duration: ScreenHeight 
 
     } 
 
    }); 
 
//create scene 
 
    $("#owlZone").each(function(index){ 
 

 
      new ScrollMagic.Scene({ 
 
       triggerElement: this 
 
      }) 
 
       .setPin(this) 
 
       .addTo(ctrl); 
 
    }); 
 

 
// animate phone 
 
    var SMController1 = new ScrollMagic.Controller(); 
 

 
    // var tlm = new TimelineMax(); 
 
    // tlm.fromTo('#itemOne', 1, {x:0, y:0}, { x:0, y:0 }) 
 
    // .fromTo('#itemTwo', 2, {x:"0", y:0}, { x:0, y:0 }) 
 
    // .fromTo('#itemThree', 5, {x:0, y:0}, { x:0, y:0 }) 
 

 
     // .to('.toushbrush-slider', 3, {opacity:0}); 
 
     // .fromTo('#slider', 2, {}, {}); 
 
     // .to('#slider', 2, {rotation:90, left:'50%'}); 
 

 
    var scene = new ScrollMagic.Scene({ 
 
         triggerElement: "#owlZone", 
 
         duration: 1500, 
 
         triggerHook: 0.2 
 
    }) 
 
    // .setTween(tlm) 
 
    .addIndicators() 
 
    .setPin('#slider') 
 
    .addTo(SMController1); 
 

 

 
}) (jQuery); 
 
    
 

 
});
.section-block-three { 
 
    background: linear-gradient(to bottom right, #02050b 0, #0f204b 50%, #1c3b8b 100%); 
 
    background-color: #1c3b8b; 
 
    padding: 150px 0 100px; 
 
    position: relative; 
 
    } 
 

 
.mob-app__head h4 { 
 
    font-size: 50px; 
 
    font-family: "centrale_sans_light"; 
 
    position: relative; 
 
    color: #fff; 
 
    font-weight: 300; 
 
    } 
 

 
.mob-app__head p { 
 
    margin: 20px 0; 
 
    color: #fff; 
 
    font-size: 30px; 
 
    line-height: 35px; 
 
    } 
 

 
.mob-app__content p { 
 
    line-height: 23px; 
 
    color: #fff; 
 
    font-size: 20px; 
 
    } 
 

 
.mob-app__image { 
 
    background-color: lime; 
 
    -webkit-background-size: cover; 
 
      background-size: cover; 
 
    background-repeat: no-repeat; 
 
    background-position: center center; 
 
    width: 135px; 
 
    height: 549px; 
 
    } 
 

 
.mob-app__store { 
 
    margin-top: 100px; } 
 
    .mob-app__store .app-store, .mob-app__store .google-play { 
 
    -webkit-background-size: cover; 
 
      background-size: cover; 
 
    background-position: center center; 
 
    width: 150px; 
 
    height: 44px; 
 
    display: inline-block; 
 
    } 
 
    .mob-app__store .app-store { 
 
    background-color: white; 
 
    margin-right: 20px; 
 
    } 
 
    .mob-app__store .google-play { 
 
    background-color: purple; 
 
    } 
 

 
.toushbrush-slider { 
 
    overflow: hidden; 
 
    height: 350px; 
 
    margin: 100px 0 0 60px; 
 
    } 
 

 
.toushbrush-slider__images { 
 
    position: relative; 
 
    } 
 
    .toushbrush-slider__images .images__image-one, .toushbrush-slider__images .images__image-two, .toushbrush-slider__images .images__image-three { 
 
    -webkit-background-size: cover; 
 
      background-size: cover; 
 
    background-repeat: no-repeat; 
 
    background-position: center center; 
 
    width: 175px; 
 
    height: 350px; 
 
    display: inline-block; 
 
    } 
 
    .toushbrush-slider__images .images__image-one { 
 
    background-color: red; 
 
    } 
 
    .toushbrush-slider__images .images__image-two { 
 
    background-color: green; 
 
    } 
 
    .toushbrush-slider__images .images__image-three { 
 
    background-color: yellow; 
 
    } 
 
    .toushbrush-slider__images .images__content { 
 
    display: inline-block; 
 
    width: 200px; 
 
    vertical-align: top; 
 
    margin: 50px 0 0 20px; 
 
    } 
 
    .toushbrush-slider__images .images__content p { 
 
     color: #fff; 
 
     line-height: 20px; 
 
     font-size: 16px; 
 
     }
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/debug.addIndicators.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section class="section-block-three" id="owlZone"> 
 
\t \t <div class="container"> 
 
\t \t \t <div class="row"> 
 
\t \t \t \t <div class="col-md-5"> 
 
\t \t \t \t \t <div class="mob-app__head"> 
 
\t \t \t \t \t \t <h4>this is text<span></span></h4> 
 
\t \t \t \t \t \t <p><span>this is text</span> this is text</p> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <div class="mob-app__content"> 
 
\t \t \t \t \t \t <p>this is text</p> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <div class="mob-app__store"> 
 
\t \t \t \t \t \t <a href="#" class="app-store" alt="App Store"></a> 
 
\t \t \t \t \t \t <a href="#" class="google-play" alt="Google Play"></a> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class="col-md-1"> 
 
\t \t \t \t \t <div class="mob-app__image"></div> 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class="col-md-6"> 
 
\t \t \t \t \t <div class="toushbrush-slider" id="slider"> 
 
\t \t \t \t \t \t <div class="toushbrush-slider__images" id="itemOne"> 
 
\t \t \t \t \t \t \t <div class="images__image-one"></div> 
 
\t \t \t \t \t \t \t <div class="images__content"> 
 
\t \t \t \t \t \t \t \t <p>this is textthis is textthis is textthis is textthis is textthis is textthis is textthis is text</p> 
 
\t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t <div class="toushbrush-slider__images" id="itemTwo"> 
 
\t \t \t \t \t \t <div class="images__image-two"></div> 
 
\t \t \t \t \t \t <div class="images__content"> 
 
\t \t \t \t \t \t \t <p>this is textthis is textthis is textthis is textthis is textthis is textthis is textthis is text</p> 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <div class="toushbrush-slider__images" id="itemThree"> 
 
\t \t \t \t \t \t <div class="images__image-three"></div> 
 
\t \t \t \t \t \t <div class="images__content"> 
 
\t \t \t \t \t \t \t <p>this is textthis is textthis is textthis is textthis is textthis is textthis is textthis is text</p> 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t </div> 
 
\t </div> 
 
</div> 
 
</section>

답변

0

나는 IE에서 사파리, 주요 브라우저에 성능면에서 어려운시기를 몇 스크롤 플러그인을 사용하지만 항상 있었다.

내가 찾은 가장 좋은 방법은 참조 스크롤 이벤트 핸들러를 결합했다 .scroll() :

: 나는 마지막 위치에 전역 변수를 업데이트 한 다음 다른 시간 제한 처리기를 설치
$("#target").scroll(function() { 
    globalScroll = $(window).scrollTop(); 
}); 

setTimeout(function() { 
    // set your object properties according to last scroll position 
    // $('someobject').animate(...); 
}, 200 /* experiment with timeout value for performance in all browsers */) 

주 스레드가 비어있을 때 실제 처리가 수행되고 각 스크롤 이벤트 값에 대한 렌더링을 수행하지 않아 잠재적 인 느린 동작을 방지하기 때문에 많은 도움이됩니다. 안다. 성능 저하는 항상 많은 일반 시나리오에서 작동하도록 설계된 플러그인과 함께 제공되므로 특정 요구 사항에 맞게 코드를 작성하여 학습하면 큰 효과가 있습니다.

내가 downvotes를 얻을 수도 있지만, 여기에 나는 가야한다 : 당신이 조만간 문제가 될 것이기 때문에 Javascript와 코드가 어떻게 작동하는지 가능한 많이 시도해야한다. 누군가 당신을 위해 이것을 구현하면 불행히도 고객이 작은 불만을 제기 할 때까지만 도움이됩니다.

+0

답변 해 주셔서 감사합니다. – Richard