Hey guys, today in this post we are going to learn about How to Create a Simple Custom Auto Slider with Next and Previous Buttons in Javascript, Jquery and css.
Files we used in this post example:
nextPreviousSlider.html | HTML File | It is used for create a image slider with next previous button for display the browser. |
nextprevious.js |
JavaScript File | It is holding Next and Previous JavaScript Functioality. |
nextPrevious.css | Style CSS File | It is used for Image slider and Button Alignment. |
jQuery Library | JQuery Library Min File | It is a JQuey Library that is provided by JQuery |
Download Supported jQuery Library for Custom Banner Rotating Image with Text Slider.
Final Output
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
Step 1:- Create HTML File : nextPreviousSlider.html
nextPreviousSlider.html [HTML File]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>jquery slider with next previous buttons</title>
<script type="text/javascript" src="http://w3web.net/wp-includes/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="include/nextPrevious.js"></script>
<link rel="stylesheet" href="include/nextPrevious.css" type="text/css" media="all">
</head>
<body>
<div id="sliderContainer">
<a href="javascript:void(0)" id="pre" title="Previous"><abbr style="font-size:80px;">◃</abbr></a>
<a href="javascript:void(0)" id="nxt" title="Next"><abbr style="font-size:80px;">▹</abbr></a>
<ul class="slideList">
<li><img src="https://www.w3web.net/wp-content/uploads/2020/08/w3webSlider1.png" width="300" height="200" alt="w3web.net Auto Next Previous Javascript Slider Plugin"></li>
<li><img src="https://www.w3web.net/wp-content/uploads/2020/08/w3webSlider2.png" width="300" height="200" alt="w3web.net Auto Next Previous Javascript Slider Plugin"></li>
<li><img src="https://www.w3web.net/wp-content/uploads/2020/08/w3webSlider3.png" width="300" height="200" alt="w3web.net Auto Next Previous Javascript Slider Plugin"></li>
<li><img src="https://www.w3web.net/wp-content/uploads/2020/08/w3webSlider4.png" width="300" height="200" alt="w3web.net Auto Next Previous Javascript Slider Plugin"></li>
</ul>
</div>
<br/>
<!--Start RelatedTopics Section-->
<div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
<br/><br/>
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
<div style="display:block; overflow:hidden;">
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
<li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
<li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
<li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
</ul>
</div>
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
<li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
<li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
<li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
</ul>
</div>
<div style="clear:both;"></div>
<br/>
<div class="youtubeIcon">
<a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
</div>
</div>
</div>
<!--End RelatedTopics Section-->
</body>
</html>
Step 2:- Create JavaScript File : nextPrevious.js
nextPrevious.js [JavaScript File]
$(document).ready(function(){
$('#sliderContainer').slideRotate();
})
$.fn.slideRotate=function(){
var thisObj = $(this);
thisObj.find('ul.slideList li').not(':first').hide();
thisObj.append("<div id='roundList'></div>");
$('ul.slideList li').each(function(i){
$('#roundList').append("<a href='#'>"+i+"</a>");
$(this).attr('id', i);
})
var i=0;
var lastIndex = 0;
var indexCount = $("ul.slideList li").index();
var roundCount = $('#roundList a').index();
$('#nxt').click(function(){
nxtPly();
})
function nxtPly(){
i++;
if($("ul.slideList li:last").css('display')=='list-item')
{
i=0;
}
$('#pre').removeClass('active');
$("#roundList a").removeClass('active');
$("#roundList a:eq("+i+")").addClass('active');
$("ul.slideList li").hide();
$("ul.slideList li:eq("+i+")").show();
}
$('#pre').click(function(){
prePly();
})
function prePly(){
i--;
if($("ul.slideList li:first").css('display')=='list-item')
{
i=indexCount;
$('#pre').addClass('active');
}
$('#nxt').removeClass('active');
$("#roundList a").removeClass('active');
$("#roundList a:eq("+i+")").addClass('active');
$("ul.slideList li").hide();
$("ul.slideList li:eq("+i+")").show();
}
var timeSpan = setInterval(function(){nxtPly()}, 5000);
$("#roundList a:first").addClass('active');
$('#pre, #nxt, #roundList a').hover(function(){
clearInterval(timeSpan);
}, function(){
timeSpan = setInterval(function(){nxtPly()}, 5000);
});
$('#roundList a').click(function(){
var roundTxt = $(this).text();
$("#roundList a").removeClass('active');
$(this).addClass('active');
$("ul.slideList li").hide();
$("ul.slideList li:eq("+roundTxt+")").show();
});
}
Step 3:- Create Style CSS : nextPrevious.css
nextPrevious.css [Style CSS File]
body{ font-family:Arial, Helvetica, sans-serif;}
#sliderContainer{ width:300px; margin:auto; position:relative;}
ul.slideList{ margin:0; padding:0; list-style:none;}
ul.slideList li{ width:300px; float:left; height:200px; position:absolute; border:1px #ccc solid; padding:5px;}
a#pre{ font-size:16px; position:absolute; text-decoration:none; left:-50px; top:45px; padding:3px 10px;}
a#pre:hover, a#pre.active { color:#FF0000; text-decoration:none;}
a#nxt{ font-size:16px; position:absolute; text-decoration:none; right:-60px; top:45px; padding:3px 10px;}
a#nxt:hover, a#nxt.active{ color:#FF0000; text-decoration:none;}
#roundList{ font-size:12px; color:#000000; position:absolute; top:190px; left:10px;}
#roundList a{ color:#FFFFFF; text-decoration:none; background:#0033FF; float:left; margin-right:5px; border:1px #0033FF solid; border-radius:40px; width:10px; height:10px; text-indent:10px; overflow:hidden;}
#roundList a:hover, #roundList a.active{ background:#FF0000; border:1px #ff0000 solid;}
Further post that would you like to learn in Salesforce
What is a slider image?
A slider is basically a slideshow of images, text, and/or videos that may either automatically scroll or allow visitors to scroll through the content.
What is image slider in JavaScript?
JavaScript Image Slider does not only involve JavaScript, but you can play with HTML and CSS to create an Image Slider. In a simpler way, It is a slider that allows showing multiple images on a web application.
How do I connect JavaScript to HTML and CSS?
To link a CSS file with your HTML file, you have to write the next script on your HTML file inside the head tag. To link a Js file with your HTML, you only have to add the source of the script inside the body tag or outside; it doesn't matter.
Related Topics | You May Also Like
Our Free Courses →
👉 Get Free Course →
📌 Salesforce Administrators 📌 Salesforce Lightning Flow Builder 📌 Salesforce Record Trigger Flow Builder |
👉 Get Free Course →
📌 Aura Lightning Framework 📌 Lightning Web Component (LWC) 📌 Rest APIs Integration |