4.1 作业

$(fuction()){

  var $li = $('.slide_pics li');

  var len = $li.length;

  var nextli = 0;

  var nowli = 0;

  var $prev = $('.prev');

  var $next = $('.next');

  var timer = null;

 

  $li.not(':first').css({left:800});

 

  $li.each(function(index)){

  var $sli = $('<li></li>');

  if(index == 0){

    $sli.addClass('active');

    }

    $sli.appendTo('.points');

    })

   

    $points = $('.poinnts li');

   

    $points.click(function()){

    nextli = $(this).index

    if(nextli == nowli){

    return;

    }

    move();

    $(this).addClass('active').siblings().renoveClass('active');

    });

    $prev.click(function()){

    nextli--;

    move();

    $points.eq(nextli).addClass('active').siblings().removeClass('actve');

    });

    $next.click(function()){

    nextli--;

    move();

    $points.eq(nextli).addClass('active').siblings().removeClass('actve');

    });

   

    $('.slide').hover(function()){

    clearInterval(timer);

    },function(){

    timer = setInterval(autoplay,3000);

    });

   

    timer = setInterval(autoplay,3000);

   

    function autoplay(){

      nextli++;

      move();

    $points.eq(nextli).addClass('active').siblings().removeClass('actve');

     

    }

   

    function move(){

    if(nextli < 0){

    nextli = len - 1;

    nowli = 0;

    $li.eq(nextli).css({left:-800});

    $li.eq(nowli).stop().stop().animate({left:400});

    $li.eq(nowli).stop().stop().animate({left:0});

    nowli = nextli;

    return;

    }

   

    if(nextli > len - 1){

    nextli = 0;

    nowli = len - 1;

    $li.eq(nextli).css({left:-800});

    $li.eq(nowli).stop().stop().animate({left:400});

    $li.eq(nowli).stop().stop().animate({left:0});

    nowli = nextli;

    return;

    }

    if(nextli > nowli){

    $li.eq(nextli).css({left:600});

    $li.eq(nowli).stop().animate({left: 800});

    }else{

    $li.eq(nextli).css({left: -800});

    $li.eq(nowli).stop().animate({left: 800});

    }

    $li.eq(nextli).stop().animate({left: 0});

    nowli = nextli;

    }

    })

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容