0

我有一个非常好的工作滑块,但我需要像导航的工作方式一样稍微改变行为。

在第一张幻灯片上,我希望只有右/下一个选项可用,第 2/3/4 个等以使左和右或下一个和上一个都可用。一旦你到达最后幻灯片,下一个或右选项将被隐藏,因此它不会循环播放。

这是我的脚本。

jQuery(document).ready(function ($) {

  $('#checkbox').change(function(){
    setInterval(function () {
        moveRight();
    }, 3000);
  });

    var slideCount = $('#slider ul li').length;
    var slideWidth = $('#slider ul li').width();
    var slideHeight = $('#slider ul li').height();
    var sliderUlWidth = slideCount * slideWidth;

    $('#slider').css({ width: slideWidth, height: slideHeight });

    $('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });

    $('#slider ul li:last-child').prependTo('#slider ul');

    function moveLeft() {
        $('#slider ul').animate({
            left: + slideWidth
        }, 200, function () {
            $('#slider ul li:last-child').prependTo('#slider ul');
            $('#slider ul').css('left', '');
        });
    };

    function moveRight() {
        $('#slider ul').animate({
            left: - slideWidth
        }, 200, function () {
            $('#slider ul li:first-child').appendTo('#slider ul');
            $('#slider ul').css('left', '');
        });
    };

    $('a.control_prev').click(function () {
        moveLeft();
    });

    $('a.control_next').click(function () {
        moveRight();
    });

});

4

2 回答 2

0

on moveLeft and moveRight functions you could check $('#slider ul').attr("left") attribute. If it's 0 you are on first slide if it's equal to ($('#slider ul').attr("width") - ($('#slider ul li').attr("width"))) you are on the last.

于 2013-10-01T10:26:46.733 回答
0
function moveLeft() {
    if($('#slider ul').position().left > 0){
     $('#slider ul').animate({
         left: + slideWidth
     }, 200, function () {
         $('#slider ul li:last-child').prependTo('#slider ul');
         $('#slider ul').css('left', '');
     });
    }
};
function moveRight() {
    if($('#slider ul').position().left < (sliderUlWidth - slideWidth)){
     $('#slider ul').animate({
         left: + slideWidth
     }, 200, function () {
         $('#slider ul li:last-child').prependTo('#slider ul');
         $('#slider ul').css('left', '');
     });
    }
};
于 2013-10-01T10:40:34.920 回答