0

我已经编写了一个内容滑块代码,并且可以在正确单击时从右向左滑动内容。

但是,如果我必须从左向右滑动内容,我必须第一次在左箭头按钮上单击两次,然后单击从左向右滑动。

另外,一旦我开始从左向右滑动内容,如果我必须从右向左滑动内容,我必须第一次双击右箭头按钮两次。

下面是代码。

<head>
    <title></title>
</head>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery-1.8.1.min.js">

</script>
<script type="text/javascript" src="js/jquery.easing.1.3.js">

</script>
<!--script type="text/javascript" src="js/slidR.js"> </script-->

<body>
    <div id="sliderBlock">
        <div id="slide1" class="slide">
            <img src="img/nmo.jpg" />
        </div>
        <div id="slide2" class="slide">
            <img src="img/tys.jpg" />
        </div>
        <div id="slide3" class="slide">
            <img src="img/ups.jpg" />
        </div>
        <div id="slide4" class="slide">
            <img src="img/we.jpg" />
        </div>
    </div>
</body>
<script>
    $(function () {
        var count = $("#sliderBlock").children().length;
        var slideWidth = $(".slide").outerWidth();
        var slideHeight = $(".slide").outerHeight();
        var totalWidth = count * slideWidth;
        var easeFn = "swing";
        var fs = 1;
        var ls = count;
        var currentSlide;
        $("#sliderBlock").append("<div id='next'></div>")
        $("#sliderBlock").append("<div id='prev'></div>")
        $(".slide").wrapAll('<div id="allSlides">');
        $("#allSlides").css({
            "width": totalWidth,
            "height": slideHeight
        });
        $("#sliderBlock").append("<ul id='pagination'>");
        for (i = 1; i <= count; i++) {
            $("#pagination").append("<li><a id='slide" + i + "'>" + i + "</a></li>")
        }
        $("#pagination li a#slide1").addClass("liveSlide");
        var interval = 3000;
        var timeInterval = setInterval(function () {
            slidR()
        }, interval);
        $("#prev").on("click", slidR_L)
        $("#next").on("click", slidR_R)

        function slidR() {

            //  slidR_R();
            //  slidR_L();

        }
        var curSlide, curSlideNo, prevSlideNo, divReOrder;
        divReOrder = 1;

        function slidR_R() {

            $("#allSlides").animate({
                left: -slideWidth
            }, 1000, function () {
                $(".slide:first-child").clone().appendTo("#allSlides");
                $(".slide:first-child").detach();
                $("#allSlides").css('left', "0px");
            });

        }

        function slidR_L() {

            $("#allSlides").animate({
                left: "0"
            }, 1000, function () {

                $(".slide:last-child").clone().prependTo("#allSlides");
                $(".slide:last-child").detach();
                $("#allSlides").css('left', -slideWidth);
            });

        }
    });
</script>

4

1 回答 1

1

试试这个,看看是否有帮助:

<script>

        function slidR_R() {
            $("#allSlides").animate({
                left: -slideWidth
            }, 1000, function () {
                $(".slide:first-child").clone().appendTo("#allSlides");
                $(".slide:first-child").detach();
                $("#allSlides").css('left', "0px");
            });
        }

        function slidR_L() {
            $("#allSlides").animate({
                left: "0"
            }, 1000, function () {

                $(".slide:last-child").clone().prependTo("#allSlides");
                $(".slide:last-child").detach();
                $("#allSlides").css('left', -slideWidth);
            });
        }
    $(function () {
        var count = $("#sliderBlock").children().length;
        var slideWidth = $(".slide").outerWidth();
        var slideHeight = $(".slide").outerHeight();
        var totalWidth = count * slideWidth;
        var easeFn = "swing";
        var fs = 1;
        var ls = count;
        var currentSlide;
        $("#sliderBlock").append("<div id='next'></div>")
        $("#sliderBlock").append("<div id='prev'></div>")
        $(".slide").wrapAll('<div id="allSlides">');
        $("#allSlides").css({
            "width": totalWidth,
            "height": slideHeight
        });
        $("#sliderBlock").append("<ul id='pagination'>");
        for (i = 1; i <= count; i++) {
            $("#pagination").append("<li><a id='slide" + i + "'>" + i + "</a></li>")
        }
        $("#pagination li a#slide1").addClass("liveSlide");
        var interval = 3000;
        var timeInterval = setInterval(function () {
            slidR()
        }, interval);
        $("#sliderBlock").on("click", "#prev", slidR_L);
        $("#sliderBlock").on("click", "#next", slidR_R);

        var curSlide, curSlideNo, prevSlideNo, divReOrder;
        divReOrder = 1;


    });
</script>
于 2013-01-09T18:40:35.890 回答