0

我得到了这个简单的水平幻灯片(我已经做了一段时间了),用左/右按钮来导航它。它没有“连续”播放 - 单击相应按钮时返回开头或结尾。这是jQuery代码:

var menuItem_place = 0;
var menuItem_position = 0;
var menuItem_limit = parseInt($('.menuItem').length) - 1;

$('.menuItem:first .content').css({margin: 0, height: '100%', lineHeight: '99px'})

// Rocks menu scroll LEFT button mouse events
$('#rocksMenu_btnLeft').on('mouseenter', function(){
  $(this).animate({'background-position-x':'-26px'}, 150);
});
$('#rocksMenu_btnLeft').on('mouseleave', function(){
  $(this).stop(true).animate({'background-position-x':'-52px'}, 150);
});
$('#rocksMenu_btnLeft').on('click', function(){
  $(this).animate({'background-position-x':'0px'}, 150,
    function(){
      $(this).animate({'background-position-x':'-26px'}, 150);
      // Slide items backward
      if (menuItem_place > 0){
       menuItem_place --;
      }
      menu_animateClick();
    }
  );
});

// Rocks menu scroll RIGHT button mouse events
$('#rocksMenu_btnRight').on('mouseenter', function(){
  $(this).animate({'background-position-x':'-26px'}, 150);
});
$('#rocksMenu_btnRight').on('mouseleave', function(){
  $(this).stop(true).animate({'background-position-x':'0px'}, 150);
});
$('#rocksMenu_btnRight').on('click', function(){
  $(this).animate({'background-position-x':'-52px'}, 150,
    function(){
      $(this).animate({'background-position-x':'-26px'}, 150);
      // Slide items forward
      if (menuItem_place < menuItem_limit){
        menuItem_place ++;
      }
      menu_animateClick();
    }
  );
});

function menu_animateClick() {
    menuItem_position = 0 - (menuItem_place * 200);
    $('#menuContainer').stop().animate({left: menuItem_position + 'px'}, 300);
}

我想将该功能添加到我的代码中 - FIDDLE

谢谢。

佩德罗

4

1 回答 1

0

我在 menuItem_place 的每次递增和递减中添加了一个 else 语句。

if(menuItem_place > 0)
       menuItem_place --;
        else
      menuItem_place  =3;  

  if (menuItem_place < menuItem_limit){
    menuItem_place ++;
  }
    else
     menuItem_place = 0;  

http://jsfiddle.net/64tu2/4/

于 2013-04-22T07:43:32.907 回答