Minimal jQuery Plugin For Responsive Background Image Auto Slideshow

File Size: 778 KB
Views Total: 2877
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Minimal jQuery Plugin For Responsive Background Image Auto Slideshow

JS Background Slider is an extremely simple jQuery plugin which enables you to cycle through a set of images at a certain interval as like a full page background slideshow.

How to use it:

1. Load the jQuery JS background slider plugin's javascript in the page and make sure to have the jQuery library loaded as well.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="slider.js"></script>

2. Create a background container and insert background images into it using Html unordered list.

<div id="bg">
<ul class="slider">
<li><img src="img/slide1.jpg"></li>
<li><img src="img/slide2.jpg"></li>
<li><img src="img/slide3.jpg"></li>
<li><img src="img/slide4.jpg"></li>
</ul>
</div>

3. The required CSS to style the slideshow and make the plugin responsive for mobile, desktop, laptop, tablet devices.

#bg {
/* set first background image! */
background-image: url('img/slide1.jpg');
position: absolute;
min-width: 100%;
overflow: hidden;
background-size: cover;
background-position: center;
}
/* Smartphones ----------- */
@media only screen and (max-width : 767px) {
#bg {
/* set height of background slider */
height: 50%;
}
#overlay {
margin: 0;
left: 0;
width: auto;
top: 50%; /* set same value as height of #bg */
height: auto; /* use height: auto; to make it adjust to its contents */
}
}

/* Tablet ----------- */
@media only screen and (min-width : 768px) and (max-width : 1023px) {
#bg {
height: 100%;
}
#overlay {
/* set height and width of overlay element */
width: 700px;
height: 380px;
top: 50%;
margin-top: -230px; /* divide height by 2 */
left: 50%;
margin-left: -400px; /*divide width by 2 */
}
}
/* Desktops and laptops ----------- */
@media only screen and (min-width : 1024px) {
#bg {
height: 100%;
}
#overlay {
/* set height and width of overlay element */
width: 700px;
height: 380px;
top: 50%;
margin-top: -230px; /* divide height by 2 */
left: 50%;
margin-left: -400px; /* divide width by 2 */
}
}

5. Optionally, you can custom the time of interval in milliseconds in the slider.js.

var interval = 5000

This awesome jQuery plugin is developed by TomasVink. For more Advanced Usages, please check the demo page or visit the official website.