滑块按钮功能

时间:2014-10-06 18:34:29

标签: javascript jquery css button slider

我有一个完美的滑块,除了让磁盘动画到相应的幻灯片。我想,因为我有幻灯片改变无限循环的数量,它会让光盘按钮选择它们。如果有人有修复,请分叉我的代码。

http://codepen.io/Spiderian/pen/IKvah

以下是相关代码:

discs.click(function(e)
{
  console.log( slideAnimating );


  var btnIndex = discs.index(this);


  if(!slideAnimating && btnIndex !== slideNumber)
  {

    timerFunction.pause();


    nextSlide = btnIndex;


    changeSlide();
  }

1 个答案:

答案 0 :(得分:1)

你的问题不在disc.click中,而是在changeSlide()中。

通过此编辑,它将起作用:

function changeSlide()
{

  slideAnimating = true;

  console.log( "slide out => " + slideNumber );
  console.log( "slide IN => " + nextSlide + "\n" );

  currentDisk = nextSlide; // Edit #1

  TweenMax.to( discs.eq(slideNumber), 1, {backgroundColor:"#ffffff", borderColor:"#f10000"});

  TweenMax.to(slides[slideNumber], duration,
    {
      left:"-100%",
      onComplete:function()
      {

        slideAnimating = false;

        timerFunction.restart(true);

        if( wrapper.hasClass( "mouse-over" ) )
        {
          timerFunction.pause();
        }

        TweenMax.set(this.target, {left:"100%"});
      }
    });

  TweenMax.fromTo( discs.eq(currentDisk), 1, {backgroundColor:"#ffffff", borderColor:"#f10000"}, {backgroundColor:"#f10000", borderColor:"#ffffff"});

  TweenMax.to(slides[nextSlide], duration,
    {
      left:"0%"
    });

  if( nextSlide < totalSlides -1 )
  {

    slideNumber = nextSlide;

    nextSlide++;
  }
  else
  {

    slideNumber = nextSlide;

    nextSlide = 0;
    console.log("first slide!!");
  }

}