【问题标题】:How to go to next slides jQuery如何转到下一张幻灯片 jQuery
【发布时间】:2019-08-20 14:35:12
【问题描述】:

我对此代码有疑问:Codepn project

我希望每次向下滚动时都会显示下一部分。同时,只有第二个正在显示...

我还希望它使用鼠标滚动顶部返回到上一张幻灯片

我想得到的效果:LOOK THIS WEBSITE

显示我正在使用:

function handleMouseWheelDirection( direction )
{
    console.log( direction ); // see the direction in the console    

    if ( direction == 'down' ) {

        goNextSlide();        

    } else if ( direction == 'up' ) {

        goPrevSlide();    

    } else {
        // this means the direction of the mouse wheel could not be determined
    }
}

goNextSlide 函数:

const goNextSlide = () =>{
    TweenMax.to(sectionMain, 2, {x:0, y:-100} );
    TweenMax.to(slide1, 0, {delay:0.4, x:0, y:0, ease: Power4.easeOut, display:"block" } );        
}

请查看 codepen,以便更好地了解我。有任何想法吗?谢谢。

【问题讨论】:

  • 嘿西蒙。我强烈建议在this page 上修改 Craig 的演示,因为它将解决您的很多问题,而不必自己编写代码。一般来说,the GreenSock forums 是更快获得高质量帮助的更好地方。

标签: javascript jquery html css gsap


【解决方案1】:

我认为您应该添加一个索引来识别用户当前所在的部分。

例如这样的:

var caseIndex = 0;
const numOfSections = 3;
function handleMouseWheelDirection( direction )
{
    if(caseIndex < numOfSections) {
      caseIndex++;    
    }else{
      caseIndex=0 
    } 

    if ( direction == 'down' ) {
        goNextSlide(caseIndex);
    } else if ( direction == 'up' ) {
        goPrevSlide();

    } else {
        // this means the direction of the mouse wheel could not be determined
    }
}

然后当您滑动到下一个滚动条时 - 由它的索引标识:

const goNextSlide = (slideIndex) =>{
    TweenMax.to(sectionMain, 2, {x:0, y:-100*slideIndex} );
    TweenMax.to(eval('slide'+slideIndex), 0, {delay:0.4, x:0, y:0, ease: Power4.easeOut, display:"block" } );
}

在我的示例中,“section_main”更改为“case_0

所以这是下一张幻灯片的基本工作,你明白了,所以尝试对上一张幻灯片做同样的事情。

【讨论】:

  • 感谢您的回复。我已经更新了我的代码,现在好多了,但我仍然不知道如何让滚动顶部工作。问题是每次我使用滚动(向上或向下)时,该函数都会计算下一个索引......我做错了什么?你能偷看吗?这是新codepen的链接codepen.io/GGQa/pen/WNeGmJz
  • @Simon 请关注这个:codepen.io/deadlyacid/pen/rNBWMGV
  • 完美。谢谢你:)
  • 你还知道如何在动画期间阻止滚动吗?现在我可以使用滚动 100 次,并观看页面跟随索引 100 次......如果可以在动画之后使用下一个滚动,那将是理想的。
  • 好吧,这很简单,只要 (tl && tl.isActive()) { return; }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-09
  • 1970-01-01
  • 2021-01-17
  • 2017-05-21
  • 2017-09-27
  • 1970-01-01
  • 2015-11-20
相关资源
最近更新 更多