简体   繁体   English

滚动触摸支持 animation

[英]Touch support for Scrolling animation

I have some problem with my code.我的代码有问题。 I'm using GSAP for scrolling full height of my page.我正在使用 GSAP 滚动页面的全高。 Everything working nice on desktop using scroll but on mobile I cant swiping.. Because to scroll I used that code:使用滚动在桌面上一切正常,但在移动设备上我无法滑动。因为滚动我使用了该代码:

if ( direction == 'down' ) {

if(caseIndex < numOfSections) {
    caseIndex++;    

if(caseIndex == 1){
    scrollBottom1(caseIndex);       
}

if(caseIndex == 2){ 
    scrollBottom2(caseIndex);
}

if(caseIndex == 3){
    scrollBottom3(caseIndex);
}
  }   
}

My function for ScrollBottom1 ;我的 function 用于ScrollBottom1

   const scrollBottom1 = (caseIndex) =>{
        tl1.play();
    }

My TimeLineMax animation:我的 TimeLineMax animation:

  var tl1 = new TimelineMax({pasused: true});
      tl1.to(slide1,0,{display:"block"})
      .to(".hide-text", 1, {y:"100%",ease:Power3.easeIn},"slide1" )
      .to(".slogan", 0.5, {delay:"0.5",y:"-100%"},0 )
      .to(slide0,1.5,{delay:"0.3",y:"-100vh",ease:Power3.easeInOut}, 0)
      .to(slide1,1.5,{delay:"0.3",y:"0vh", ease:Power3.easeInOut }, 0)
      .to(toggleNavi,0,{backgroundColor:"#fff"})
      .to(slide0,0,{display:"none", y:"0"})
      .to(slide1,0,{y:"0",})      
       tl1.paused(true);

I can't use Event listener like:我不能像这样使用事件监听器:

window.addEventListener("mousemove", scrollBottom1);
window.addEventListener("touchstart", scrollBottom1);
window.addEventListener("touchmove", scrollBottom1);

cause it's working just for first slide...因为它只适用于第一张幻灯片......

I have some inspiration for resolve my problem:我有一些解决问题的灵感:

var lastY;

$(document).bind('touchmove', function(e) {

    var currentY = e.originalEvent.touches ? e.originalEvent.touches[0].pageY : e.pageY;

    if (Math.abs(currentY-lastY) < 10) { return; }

    if (currentY > lastY) {

        alert('down');

    } else {

        alert('up');
    }

    lastY = currentY;

});

But I have no idea it's good or not.. Can anyone help me with this?但我不知道它好不好..有人可以帮我吗? Thanks!谢谢!

I found solution for this.我找到了解决方案。

var ts;
$('.case_0').bind('touchstart', function (e){
   ts = e.originalEvent.touches[0].clientY;
});

$('.case_0').bind('touchend', function (e){


    if (tl1 && tl1.isActive()) {
        return;
    }

    if (tl2 && tl2.isActive()) {
        return;
    }

    if (tl3 && tl3.isActive()) {
        return;
    }


   var te = e.originalEvent.changedTouches[0].clientY;
   if(ts > te+5){
    tl1.play();
   }else if(ts < te-5){
    tl1.reverse();
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM