Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <html>
    <head>
        <title>
            Study task | Slider plugin
        </title>
        <meta content="" name="description"/>
        <meta content="" name="keywords"/>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
        <link href="css/application.css" rel="stylesheet"/>
        </script>
        <script src="js/slider.js">
        </script>
    </head>
    <body>
        <div class="container">



            <div class="container_row">
                <!-- First slider -->
                <div class="slider slider_first" id="slider">
                    <div class="slider_viewport">
                        <div class="slider_list">
                            <div class="slider_item">                                
                                <div class="slider_item-content">Headering 1</div>
                                <img src="http://wallppapers.ru/wallpapers/original/F1654107041B-2.jpg"/>                                                               
                            </div>
                            <div class="slider_item">                                
                                <div class="slider_item-content">Headering 2</div>
                                <img src="http://widefon.com/_ld/145/05247707.jpg"/>                                                               
                            </div>
                            <div class="slider_item">                                
                                <div class="slider_item-content">Headering 3</div>
                                <img src="https://www.planwallpaper.com/static/images/542a0313e9630e447a47564717f1714e.jpg"/>                                                               
                            </div>
                            <div class="slider_item">                                
                                <div class="slider_item-content">Headering 4</div>
                                <img src="https://i.pinimg.com/originals/ca/24/e3/ca24e3efd89a0d7244e5ec2f68afa114.jpg"/>                                                               
                            </div>
                        </div>
                    </div>
                    <div class="slider_nav">
                        <div class="slider_arrow slider_arrow__left">
                        </div>
                        <div class="slider_arrow slider_arrow__right">
                        </div>
                    </div>
                </div>
            </div>



            <div class="container_row">
                <!-- Second slider. Carousel -->
                <div class="slider slider_second" id="carousel">
                    <div class="slider_viewport">
                        <div class="slider_list">
                            <div class="slider_item">
                                <div class="slider_item-inner">
                                    <img src="http://wallppapers.ru/wallpapers/original/F1654107041B-2.jpg"/>
                                </div>                                
                            </div>
                             <div class="slider_item">
                                <div class="slider_item-inner">
                                    <img src="http://widefon.com/_ld/145/05247707.jpg"/>
                                </div>                                
                            </div>
                             <div class="slider_item">
                                <div class="slider_item-inner">
                                    <img src="https://www.planwallpaper.com/static/images/542a0313e9630e447a47564717f1714e.jpg"/>
                                </div>                                
                            </div>
                             <div class="slider_item">
                                <div class="slider_item-inner">
                                    <img src="https://i.pinimg.com/originals/ca/24/e3/ca24e3efd89a0d7244e5ec2f68afa114.jpg"/>
                                </div>                                
                            </div>
                        </div>
                    </div>
                    <div class="slider_nav">
                        <div class="slider_arrow slider_arrow__left">
                        </div>
                        <div class="slider_arrow slider_arrow__right">
                        </div>
                    </div>
                </div>
            </div>


            
        </div>
    </body>
</html>

              
            
!

CSS

              
                *, *::before, *::after {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: #222;
    color: #eee;
    font: 14px/24px Arial, serif;
    position: relative;
}

/* Container */
.container {
}

.container_row {
    margin: 80px 40px;
    text-align: center;
}

/* Slider */
.slider {
    user-select: none;
    display: inline-block;
    position: relative;
}

.slider_first {
    width: 460px;
}

.slider_second {
    width: 100%;
}

.slider_viewport {
    position: relative;
    overflow: hidden;
    width: 100%;
}

.slider_list {
    transition: all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
    display: flex;
    flex-flow: row nowrap;    
}

.slider_item {
    flex-shrink: 0;
    position: relative;
}

.slider_item img {
    display: block;
    width: 100%;
    height: auto;
}
.slider_item-content{
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    font-size: 40px;
    font-weight: 700;
    text-shadow: 2px 2px 1px #333;
    padding: 20px;
    text-align: center;
    background: rgba(0,0,0,0.5);
}
.slider_nav.is-disabled {
    display: none;
}

.slider_control-nav {
    position: absolute;
    z-index: 999;
    left: 0;
    right: 0;
    bottom: -50px;
    text-align: center;
}

.slider_control-nav-item {
    transition: all 0.5s linear;
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin: 0 5px;
    cursor: pointer;
    background: #fff;
}

.slider_control-nav-item:hover {
    opacity: 0.3;
}

.slider_control-nav-item.is-active {
    opacity: 0.3;
    cursor: default;
}

.slider_arrow {
    position: absolute;
    top: 50%;
    margin-top: -25px;
    width: 26px;
    height: 49px;
    z-index: 999;
    cursor: pointer;
}

.slider_arrow.is-disabled {
    cursor: default;
    opacity: 0.5;
}

.slider_arrow:hover {
    opacity: 0.5;
}

.slider_arrow__right {
    right: 20px;
    background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAxCAYAAADEIbk7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAPVJREFUeNrUmNsJwjAUhqM71BkEp3AbXc0lXKKu4IsL+BZPMQUJ2uZy/g8M/KVNDnw0l3NJiDGeTIMpKLWJ0zOEm+loegRR2ybIwXQ1DSpQSNM2xncbVdM4v8hhnx9SWN4hg33rlMB+DbjDlgZdYWsGbrASIxdYqWE3rMa4C1Y7Bc2wloVtgrVu12pYzyGsgvW6lmKYh8MsgnmFgVWYZ3BbhHmH7By2U4Fy2H2GqfK4vemZYJe//iNkjZBdh5wjxDMgvg7x3kg8QiIskjMgWRCS1yGZKpJ7I9UEUh8hFR9SwyJVOXLPgN2cyCH47dZZDZnaS4ABADgyNPpHIY0vAAAAAElFTkSuQmCC) no-repeat 0 0;
}

.slider_arrow__left {
    left: 20px;
    background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAxCAYAAADEIbk7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAONJREFUeNq82M0NwjAMhuEgdYUwAxKLcWExlmAJZmAGbqkDVAJE2vz4eyNZrXp5FLV1bIeUUhBGtDjl+ynoVrS4WhwtJuVObum18jUiSH6OIN5QEfGEVhEvaBPxgKqQUagaGYGakF6oGemBupBWqBtpgYaQWmgYqYFckC3IDVmDXJES5I78gyTILyRDPqG9ElmgjNyVyAJd3sjD4qCq8dAdYe8I/erQ/wjNDGiuQ7M3eh6hJyxaM6BVEFrXoZUqWnuj3QTaH6EdH9rDol05OmdAJydFbPfU9NOts3JW9zWvmwUYACVWyckfytVNAAAAAElFTkSuQmCC) no-repeat 0 0;
}

.slider__carousel {
    overflow: hidden;        
}

.slider__carousel::before, .slider__carousel::after {
    content: "";
    width: 150px;
    position: absolute;
    top: -5px;
    bottom: -5px;
    z-index: 200;
}

.slider__carousel::before {
    left: -5px;
    background: -webkit-linear-gradient(left, #fff 10%, transparent);
    background: linear-gradient(to right, #fff 10%, transparent);
}

.slider__carousel::after {
    right: -5px;
    background: -webkit-linear-gradient(right, #fff 10%, transparent);
    background: linear-gradient(to left, #fff 10%, transparent);
}

.slider__carousel .slider_viewport {
    overflow: visible;
    width: 250px;
    margin: 0 auto;
}

.slider__carousel .slider_arrow__left {
    left: 70px;
}

.slider__carousel .slider_arrow__right {
    right: 70px;
}
              
            
!

JS

              
                (function($) {
    $.extend($.fn, {
        skySlider: function(options) {
            if (!this.length) {
                if (options && options.debug && window.console) {
                    console.warn("Nothing selected, return nothing.");
                }
                return;
            }
            var plgSlider = $.data(this[0], "skySlider");
            if (plgSlider) {
                return plgSlider;
            }
            options = options || {};

            plgSlider = new slider(options, this[0]);
            $.data(this[0], "skySlider", plgSlider);

            return plgSlider;
        }
    });
    var slider = function(options, container) {
        this.namespace = "plgSlider-" + (+new Date());
        this.settings = $.extend(true, {}, slider.defaults, options);
        this.container = container;
        this.init();
    };
    /**************************************************************************/
    $.extend(slider, {
        defaults: {
            interval: 3000,
            carousel: false,
            duration: 500,
            items: 1,
            loop: false,
            autoplay: false,
            callback: function() {}
        },
        prototype: {
            init: function() {                
                this.container = $(this.container);
                this.viewPort = this.container.find('.slider_list');
                this.slides = this.container.find('.slider_item');
                this.slideItemCount = this.slides.length;
                this.slideItemWidth = 100 / this.settings.items;
                this.slideSetsCount = Math.ceil(this.slideItemCount / this.settings.items);
                this.currentSlideSets = 0;
                this.isAnimated = false;

                this.controls = {
                    bullets: this.createBullets(this.container),
                    prev: this.container.find('.slider_arrow__left'),
                    next: this.container.find('.slider_arrow__right')
                };

                this.callback = $.Callbacks();
                this.callback.add(this.settings.callback);

                this.slides.width(this.slideItemWidth + '%');
                this.addHandlers();
                this.autoplay();            
            },
            createBullets: function(container) {
                var $bulletContainer = $('<div/>', {
                    class: 'slider_control-nav'
                });
                for (var i = 0; i < this.slideSetsCount; i++) {
                    $bulletContainer.append($('<div/>', {
                        class: 'slider_control-nav-item'
                    }));
                }
                this.container.append($bulletContainer);
                var $bullets = $bulletContainer.children();
                $bullets.eq(this.currentSlideSets).addClass('is-active');
                return $bullets;
            },
            addHandlers: function() {
                var that = this;
                this.controls.next.on('click', function() {
                    that.currentSlideSets++;
                    that.setSlide();
                });
                this.controls.prev.on('click', function() {
                    that.currentSlideSets--;
                    that.setSlide();
                });
                this.controls.bullets.on('click', function() {
                    that.currentSlideSets = $(this).index();
                    that.setSlide();
                });
            },
            setSlide: function() {
                if (this.isAnimated) {
                    return false;
                }
                this.isAnimated = true;
                /* change rules on first/last item */
                if ((this.settings.loop && this.currentSlideSets < 0) ||
                    (!this.settings.loop && this.currentSlideSets > this.slideSetsCount - 1)) {
                    this.currentSlideSets = this.slideSetsCount -1;
                }
                if ((!this.settings.loop && this.currentSlideSets < 0) ||
                    (this.settings.loop && this.currentSlideSets > this.slideSetsCount - 1)) {
                    this.currentSlideSets = 0;
                }
                /* detect type */
                if (this.settings.carousel) {
                    /* carousel */
                    var translateStepValue = this.currentSlideSets * 100;                    
                    this.viewPort.css({
                        'transform': 'translateX(-'+translateStepValue+'%)'
                    });
                }else {
                    /* slider */
                    var that = this;      
                    that.slides.hide();            
                    for (var i=0; i < that.settings.items;i++){                                              
                        that.slides.eq(that.currentSlideSets*that.settings.items + i).fadeIn();
                    };
                }
                this.controls.bullets.removeClass('is-active').eq(this.currentSlideSets).addClass('is-active');
                /*run callback*/
                this.callback.fire(this.currentSlideSets);

                setTimeout($.proxy(function() {
                    this.isAnimated = false;
                },this), this.settings.duration);
            },
            autoplay: function(){
                var that = this;
                if (that.settings.autoplay) {                    
                    var sliderInterval = setInterval(function() {
                        that.currentSlideSets++;
                        that.setSlide();
                        if (!that.settings.loop && that.currentSlideSets >= that.slideSetsCount - 1) {
                            clearInterval(sliderInterval);
                        }
                    }, that.settings.interval);
                }
            },
            getSlideSetsCount: function() {
                return this.slideSetsCount;
            }
        }
    });
}(jQuery));

$(document).ready(function() {
    var $slider = $('#slider').skySlider();
    var $carousel = $('#carousel').skySlider({        
        interval: 3000,
        items: 2,
        carousel: true,
        loop: true,
        autoplay: true,
        callback: function(number) {
            console.log('Current slideSet - ' + number);
        }
    });

    // console.log('Total number of slides - ' + $slider.getSlideSetsCount());
    // console.log('Total number of slides - ' + $carousel.getSlideSetsCount());
});
              
            
!
999px

Console