Slide everything into this vanilla javascript slider: just 20kb all-inclusive, no dependencies!

Overview

Lightweight vanilla javascript media and contents slider, by LCweb

Just 20KB to have:

Top features list:

  • single file, no dependencies, 100% pure javascript

  • designed to be themed with no efforts (default theme included + extra theme for demo)

  • themes mix support using prefixed selectors

  • pure CSS sliding effects (default ones: slide - fade - fadeslide - zoom-in - zoom-out)

  • slide anything. Literally. With specific support to:

    • images (with lazyloader)
    • HTML5 videos and iframes (eg. youtube embed)
    • mixed contents
  • slideshow with optional autoplay and pause-on-hover

  • carousel navigation

  • integrated touchswipe support

  • super customizable and developer-friendly (w/ public functions and events)

Tested on all mordern browsers (don't ask for old IE support please)
For live demos check: https://lcweb.it/lc-micro-slider-javascript-plugin


Installation & Usage

  1. include js/lc-micro-slider.min.js file

  2. include a theme (eg. themes/default_theme.css)

  3. initialize plugin targeting one/multiple properly composed page elements
    NB: first parameter may be a textual selector or a DOM object (yes, also jQuery objects)

Few notes anout the HTML structure:

  • the target element must contain a UL list. Each list element will be a slide
  • is suggested to use the "data-type" attribute. Possible values: image, video, iframe, mixed
    Can be globally defined using fixed_slide_type option
  • the "data-img" attributes defines slide's background and is lazyloaded

<div id="slider_wrap">
    <ul style="display: none;">
        <li data-img="../demo_assets/parrot.jpg" data-type="image">A colorful parrot!</li>

        <li data-type="video">
            <iframe style="height: 100%; width: 100%;" src="https://player.vimeo.com/video/40291524?rel=0" frameborder="0" allowfullscreen></iframe>
        </li>
        <li data-type="iframe">
            <video controls autoplay muted>
                <source src="../demo_assets/squirrel.mp4" type="video/mp4">
            </video> 
        </li>

        <li data-img="../demo_assets/cat.jpg" data-type="mixed">
            <h4 id="txt_heading">Also some plain text!</h4>
            <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo.</p> <p>Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est</p>
        </li>

    </ul>
</div>


<script type="text/javascript>
new lc_micro_slider('#slider_wrap', {
    addit_classes : ['lcms_default_theme'] // always specify which theme to use    
});
</script>

Options

Here are listed available options with default values

<script type="text/javascript>
new lc_micro_slider('#slider_wrap', {

    // (string) sliding effect / none - slide - fade - fadeslide - zoom-in - zoom-out
    slide_fx : 'fadeslide',	
    
    // (string) CSS animation easing to use / ease - linear - ease-in (etc) [supports also cubic-bezier]
    slide_easing : 'ease',	
    
    // (bool) shows navigation arrows 
    nav_arrows : true,	
    
    // (bool) shows navigation dots
    nav_dots : false,	
    
    // (bool) whether to add slideshow commands (play/pause)
    slideshow_cmd : true,		
    
    // (bool) whether to use carousel navigation
    carousel : true,	
    
    // (bool) whether to enable touch navigation
    touchswipe : true,	
    
    // (bool) whether to autostart slideshow
    autoplay : false,	
    
    // (int) animation timing in millisecods / 1000 = 1sec
    animation_time : 700, 	
    
    // (int) interval time of the slideshow in milliseconds / 1000 = 1sec
    slideshow_time : 5000, 	
    
    // (bool) whether to pause and restart slideshow on hover
    pause_on_hover : true,	
    
    // (bool) whether to pause slideshow on HTML video play 
    pause_on_video_play : false,  
    
    // (string) extra HTML code to be injected in the slider to add further commands
    extra_cmd_code : '',   
    
    // (string) defines a fixed slide type fallback. Is overrided by speific data-type attribute. Possible values: image, video, iframe, mixed
    fixed_slide_type : '',    
    
    // (string) loading animation HTML code
    loader_code : '<span class="lcms_loader"></span>', 
    
    // (array) additional classes attached to the slider wrapper. Use it also to define the attached theme
    addit_classes : [],       
});
</script>

Mixing themes

You can use multiple themes in the same page. Be sure to prefix every theme's CSS rule with the class you will use.
For example .lcms_light_theme and .lcms_dark_theme

<link href="themes/light.css" rel="stylesheet" type="text/css">
<link href="themes/dark.css" rel="stylesheet" type="text/css">

<script type="text/javascript>
new lc_micro_slider('#slider_wrap1', {
    addit_classes : ['lcms_light_theme'] // always specify which theme to use    
});

new lc_micro_slider('#slider_wrap2', {
    addit_classes : ['lcms_dark_theme'] // always specify which theme to use    
});
</script>

Public Functions

<script type="text/javascript>
const target_el = '#slider_wrap';

new lc_micro_slider(target_el, {
    addit_classes : ['lcms_default_theme']
});


// starts slideshow (pass a selector string or DOM element object)
lcms_play(target_el); 

// stops slideshow (pass a selector string or DOM element object)
lcms_stop(target_el); 

// move to a slide (pass a selector string or DOM element object)
lcms_slide(target_el, slide_index); 
</script>

Public Events

<script type="text/javascript>
const $el = document.getElementById('slider_wrap');

// dispatched whenever slider structure is ready, before injecting the first slide
$el.addEventListener('lcms_ready', (e) => {
    ...
});


// dispatched whenever very first slide is populated, before preloading
$el.addEventListener('lcms_first_populated', (e) => {
    
    // e.detail.slide_data - (object) slide data 
});


// dispatched whenever a new slide is shown (after lazyload)
$el.addEventListener('lcms_slide_shown', (e) => {
    
    // e.detail.slide_index - (int) slide index
    // e.detail.slide_data - (object) slide data 
});


// dispatched whenever a slide action is performed
$el.addEventListener('lcms_changing_slide', (e) => {
    
    // e.detail.new_index - (int) incoming slide index
    // e.detail.slide_data - (object) incoming slide data 
    // e.detail.curr_index - (int) current (to be removed) slide index
});


// dispatched whenever the new slide is in its final position
$el.addEventListener('lcms_new_active_slide', (e) => {
    
    // e.detail.new_index - (int) new slide index
    // e.detail.slide_data - (object) new slide data 
});


// dispatched whenever slider slideshow plays
$el.addEventListener('lcms_play_slideshow', (e) => {
    ...
});


// dispatched whenever slider slideshow stops
$el.addEventListener('lcms_stop_slideshow', (e) => {
    ...
});
</script>

Extra tips

Slider dynamic variables are stored in the DOM object. This might be useful to retrieve or alterate slider data.

Inspect the initial plugin's code part to know which vars are used

<script type="text/javascript>
const $el = document.getElementById('slider_wrap');

const instance = new lc_micro_slider($el, {
    addit_classes : ['lcms_default_theme']
});


// retrieve currently shown slide index
const active_index = $el.lcms_vars.shown_slide; // (int)

// know whether slideshow is playing
const active_index = $el.lcms_vars.is_playing; // (bool)


// inject a new slide and eventually refresh dots navigation
$el.lcms_vars.slides.push({
    type    : 'image',              // (string) slide type - Possible values: image, video, iframe, mixed 
    content : 'The caption!',       // (string) what you normally defines into the slide <li> tag,
    img		: 'the-image-url.jpg',  // (string|bool) data-img attribute set for <li> tag or false if not set
    classes	: ''                    // (string) eventual extra classes
});
instance.populate_dots($el);
</script>

Copyright © Luca Montanari - LCweb

You might also like...

Extract a JS/TS module and its dependencies into a new package

module-extractor Extract a module and its dependencies into a new package Usage import { extractModules } from 'module-extractor' const extraction =

Aug 9, 2022

Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported.

noist (Short for No Hoist) Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported. Why? As of npm@7 NPM suppo

Oct 27, 2022

🍞📅A JavaScript calendar that has everything you need.

🍞📅A JavaScript calendar that has everything you need.

A JavaScript schedule calendar that is full featured. Now your service just got the customizable calendar. 🚩 Table of Contents Collect statistics on

Jan 5, 2023

A lightweight, modern and customizable JavaScript slider library.

NSlider NSlider is a lightweight ( 10 KB), modern and customizable JavaScript slider library. CDN Development https://cdn.jsdelivr.net/gh/fatihege/ns

Jan 20, 2022

Pure JavaScript HTML5 Canvas Range Slider. No stylesheet needed. Simple, elegant and powerful. A quirky alternative to other sliders.

Pure JavaScript HTML5 Canvas Range Slider. No stylesheet needed. Simple, elegant and powerful. A quirky alternative to other sliders.

CanvasSlider CanvasSlider is a lightweight JavaScript range slider. Most of the range slider controls use Javascript and a stylesheet. This slider use

Aug 15, 2022

curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.

curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.

What is it ? Shaders are the new front-end web developpment big thing, with the ability to create very powerful 3D interactions and animations. A lot

Jan 1, 2023

An Obsidian plugin to grab all yaml fields from all files into a dataframe

Metadataframe Metadataframe allows you to get all metadata from your vault into CSV file. With CSV in-hand, you can do any data analysis you want with

Sep 15, 2022

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Jul 19, 2022

🤪 A linter, prettier, and test suite that does everything as-simple-as-possible.

🤪 A linter, prettier, and test suite that does everything as-simple-as-possible.

Features Fully Featured Code Grading Knowing if you need to work on your code is important- that's why we grade your code automatically. But, unlike o

Sep 25, 2022
Releases(2.0.2)
Owner
Luca
Italian web developer speciailzed in wordpress, PHP and jQuery applications. Envato elite author and one of the most popular Codecanyon publishers
Luca
Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mouse is over the marquee, and all with vanilla JavaScript.

TEG Marquee Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mou

Paul B. Joiner 0 Dec 30, 2021
Accordion Slider is a jQuery plugin that combines the functionality of a slider with that of an accordion.

Accordion Slider - jQuery slider plugin A responsive and touch-enabled jQuery accordion slider plugin that combines the functionality of a slider with

null 0 Dec 29, 2022
Open! Inclusive! Collaborative! A community for enthusiasts exploring new technologies, working on innovative ideas and helping each other grow together. Open Issues, Raise ideas, Make Pull Requests!

About Us OplnCo previously known as Devstucom represents Open Inclusive Collaborative. We as a community help our fellow students build skills through

OpInCo Community 4 Oct 13, 2022
MenuSlider-Javascript - How to create a menu slider with vanilla javascript

MenuSlider-Javascript How to create a menu slider with vanilla javascript Instal

Tarokh Mohammadi 1 Feb 8, 2022
In this project, I built a simple HTML list of To-Do tasks. This simple web page was built using Webpack, creating everything from a JavaScript index file that imported all the modules and assets

To Do List In this project, I built a simple HTML list of To-Do tasks. This simple web page was built using Webpack, creating everything from a JavaSc

Andrés Felipe Arroyave Naranjo 10 Mar 31, 2022
A full screen slide show for images and videos

Vanilla JS Slide full screen slide show for videos and images Why? This is a scratch-your-own-itch project as I wanted a way to see images and videos

Christian Heilmann 24 Oct 26, 2022
Simple customizable slide panel (without jQuery)

toolslide.js Minimalistic customizable slide panel (without jQuery) Table of contents Quick start Usage Examples Options Methods Events Browser suppor

null 5 May 23, 2022
A markdown based tool for slide deck creation.

Decker A markdown based tool for slide deck creation. Installation from source Install stack and Node.js (for npm) Clone this repo. cd decker git subm

Decker 8 Nov 7, 2022
Everything about note management. All in Zotero.

Zotero Better Notes Everything about note management. All in Zotero. User Guide(EN) | 用户指引(中文) All in Zotero: Best Note Practice Review.Writing.Best.P

null 1.3k Jan 9, 2023
Lightweight vanilla js modal component (just 2kb) , pure javascript Modal

Lightweight vanilla js modal component (just 2kb) pure javascript Modal , This is just 2kb Lightweight vanilla js modal component with zero dependenci

Salah Eddine Lalami 12 Dec 12, 2022