Создание плагина Jquery для слайдера изображений

Мне нужно преобразовать эту функцию в плагин Jquery, чтобы он мог обрабатывать любое количество изображений в барабане. Или просто любое количество изображений может быть использовано для этого слайдера. При необходимости вы можете обратиться к thirteen23.com. Я пытаюсь сделать слайдер точно так же, как на Сайте. Я новый пользователь Stack Overflow. Пожалуйста, помогите, а также скажите мне, как правильно использовать этот сайт. Заранее спасибо.Ссылка на JsFiddle

-Akshay    


  <div class="main_view">
    <div class="window">
        <div class="image_reel">
            <a href="#">
                <img width="948" src="Images/Home/LIV.jpg" alt=""></a> <a href="#">
            <img width="948" src="Images/Home/JUM.jpg" alt=""></a> <a href="#">
            <img width="948" src="Images/Home/LOV.jpg" alt=""></a> <a href="#">
            <img width="948" src="Images/Home/BLI.jpg" alt=""></a>
        </div>
        <div class="pictureslide">
            <h2>
                Livestrong</h2>
            <p>
                Mobile donations to fight cancer and improve lives.</p>
            <a href="http://thirteen23.com/work/#livestrong-donation">See more</a>
        </div>
        <div class="pictureslide">
            <h2>
                Jumpshot</h2>
            <p>
                The lighter side of serious software.</p>
            <a href="/#jumpshot">See more</a>
        </div>
        <div class="pictureslide">
            <h2>
                Flashback</h2>
            <p>
                An exciting way to explore, stylize, and share your Facebook photos.</p>
            <a href="/#flashback">See more</a>
        </div>
        <div class="pictureslide">
            <h2>
                Love Universe</h2>
            <p>
                Blurring the line between product and lifestyle.</p>
            <a href="/#love-universe">See more</a>
        </div>
    </div>
    <div class="paging">
        <a href="#" rel="1">
            <img src="Images/Home/LIV_sm.jpg" alt=""></a> <a href="#" rel="2">
        <img src="Images/Home/JUM_sm.jpg" alt=""></a> <a href="#" rel="3">
        <img src="Images/Home/LOV_sm.jpg" alt=""></a> <a href="#" rel="4">
        <img src="Images/Home/BLI_sm.jpg" alt=""></a>
    </div>
</div>

код JQuery

windowObj = {
    imageWidth: 925,
    imagesum: 4
};

var MainPageSlider = function(windowObj) {
    $(".paging a:first").addClass("active");
    //Get size of images, how many there are, then determin the size of the image reel.
    var imageWidth = windowObj.imageWidth;
    var imageSum = windowObj.imagesum + 1;
    var imageReelWidth = (imageWidth * imageSum);
    //Adjust the image reel to its new size
    $(".image_reel").css({
        'width': imageReelWidth
    });
    //Paging + Slider Function
    rotate = function() {
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * (imageWidth + 30); //Determines the distance the image reel needs to slide
        $(".paging a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500);
    };
    //Rotation + Timing Event
    rotateSwitch = function() {
        play = setInterval(function() { //Set timer - this will repeat itself every 3 seconds
            $active = $('.paging a.active').next();
            if ($active.length === 0) { //If paging reaches the end...
                $active = $('.paging a:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
        }, 7000); //Timer speed in milliseconds (3 seconds)
    };
    rotateSwitch(); //Run function on launch
    //On Hover
    $(".image_reel a").hover(function() {
        clearInterval(play); //Stop the rotation
    }, function() {
        rotateSwitch(); //Resume rotation
    });
    //On Click
    $(".paging a").click(function() {
        $active = $(this); //Activate the clicked paging
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        rotateSwitch(); // Resume rotation
        return false; //Prevent browser jump to link anchor tag
    });
};
MainPageSlider(windowObj)

Ответы на вопрос(0)

Ваш ответ на вопрос