How to Create a Simple Custom Auto Slider with Next and Previous Buttons in JavaScript, JQuery and CSS | How to Create a Simple Custom Auto Slider with Next and Previous Buttons in JavaScript

3,524 views


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

slider with next previous button in javascript -- w3web.net

 

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

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]

  1.    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>jquery slider with next previous buttons</title>
  6. <script type="text/javascript" src="http://w3web.net/wp-includes/js/jquery-1.7.1.min.js"></script>
  7. <script type="text/javascript" src="include/nextPrevious.js"></script>
  8. <link rel="stylesheet" href="include/nextPrevious.css" type="text/css" media="all">
  9.  
  10. </head>
  11.  
  12. <body>
  13. <div id="sliderContainer">
  14.      <a href="javascript:void(0)" id="pre" title="Previous"><abbr style="font-size:80px;">&ltri;</abbr></a>
  15. 	 <a href="javascript:void(0)" id="nxt" title="Next"><abbr style="font-size:80px;">&rtri;</abbr></a>
  16.     <ul class="slideList">
  17. 	    <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>
  18. 	    <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>
  19. 	    <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>
  20. 	    <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>
  21. 	</ul>
  22. </div>
  23.  
  24.  <br/>
  25.    <!--Start RelatedTopics Section-->
  26. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  27.  
  28.             <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>
  29.  
  30.             <br/><br/>
  31.             <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>
  32.             <div style="display:block; overflow:hidden;"> 
  33.                 <div style="width: 50%; float:left; display:inline-block">
  34.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  35.                         <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>
  36.                         <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>
  37.                         <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>
  38.                         <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>
  39.                         <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>
  40.                     </ul>
  41.             </div>
  42.  
  43.             <div style="width: 50%; float:left; display:inline-block">
  44.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  45.                         <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>
  46.                         <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>
  47.                         <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>
  48.                         <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>
  49.                         <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>
  50.                     </ul>
  51.                 </div>
  52.                <div style="clear:both;"></div> 
  53.                <br/>
  54.                 <div class="youtubeIcon">
  55.                     <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>
  56.                 </div>
  57.     </div>
  58.  
  59. </div>
  60.  
  61.   <!--End RelatedTopics Section-->
  62. </body>
  63. </html>

Step 2:- Create JavaScript File : nextPrevious.js

nextPrevious.js [JavaScript File]

  1.   $(document).ready(function(){
  2. 	$('#sliderContainer').slideRotate();	
  3.   })
  4.  
  5.   $.fn.slideRotate=function(){
  6.  
  7.    var thisObj = $(this);
  8.    thisObj.find('ul.slideList li').not(':first').hide();
  9.    thisObj.append("<div id='roundList'></div>");
  10.  
  11.    $('ul.slideList li').each(function(i){
  12.      $('#roundList').append("<a href='#'>"+i+"</a>");
  13. 	   $(this).attr('id', i);
  14.    })
  15.  
  16.    var i=0;
  17.    var lastIndex = 0;
  18.    var indexCount = $("ul.slideList li").index();
  19.    var roundCount = $('#roundList a').index();
  20.  
  21.    $('#nxt').click(function(){
  22.       nxtPly();
  23.    })
  24.  
  25.    function nxtPly(){      
  26.       i++;
  27.  
  28. 	  if($("ul.slideList li:last").css('display')=='list-item')
  29. 	  {
  30. 	   i=0;
  31. 	  }
  32. 	  $('#pre').removeClass('active');
  33. 	  $("#roundList a").removeClass('active');
  34. 	  $("#roundList a:eq("+i+")").addClass('active');
  35.  
  36. 	  $("ul.slideList li").hide();
  37. 	  $("ul.slideList li:eq("+i+")").show();
  38.    }
  39.  
  40.  
  41.    $('#pre').click(function(){
  42.       prePly();
  43.    })
  44.  
  45.  
  46.    function prePly(){      
  47.       i--;
  48. 	  if($("ul.slideList li:first").css('display')=='list-item')
  49. 	  {
  50. 	   i=indexCount;
  51.  
  52.  
  53. 	   $('#pre').addClass('active');
  54. 	  }
  55. 	  $('#nxt').removeClass('active');
  56.  
  57. 	  $("#roundList a").removeClass('active');
  58. 	  $("#roundList a:eq("+i+")").addClass('active');
  59.  
  60. 	  $("ul.slideList li").hide();
  61. 	  $("ul.slideList li:eq("+i+")").show();
  62.    }   
  63.  
  64.    var timeSpan = setInterval(function(){nxtPly()}, 5000);
  65.  
  66.    $("#roundList a:first").addClass('active');
  67.  
  68.  
  69.    $('#pre, #nxt, #roundList a').hover(function(){
  70.      clearInterval(timeSpan);
  71.    }, function(){
  72.        timeSpan = setInterval(function(){nxtPly()}, 5000);
  73.      });
  74.  
  75.  
  76.    $('#roundList a').click(function(){
  77.      var roundTxt = $(this).text();
  78.  
  79. 	 $("#roundList a").removeClass('active');
  80. 	 $(this).addClass('active');
  81.  
  82. 	 $("ul.slideList li").hide();
  83. 	 $("ul.slideList li:eq("+roundTxt+")").show();
  84.    });
  85.  
  86.  
  87.  }

Step 3:- Create Style CSS : nextPrevious.css

nextPrevious.css [Style CSS File]

  1.     body{ font-family:Arial, Helvetica, sans-serif;}
  2.   #sliderContainer{ width:300px; margin:auto; position:relative;}
  3.   ul.slideList{ margin:0; padding:0; list-style:none;}
  4.   ul.slideList li{ width:300px; float:left; height:200px; position:absolute; border:1px #ccc solid; padding:5px;}  
  5.  
  6.   a#pre{ font-size:16px; position:absolute; text-decoration:none; left:-50px; top:45px; padding:3px 10px;}
  7.   a#pre:hover, a#pre.active { color:#FF0000; text-decoration:none;}  
  8.   a#nxt{ font-size:16px; position:absolute; text-decoration:none; right:-60px; top:45px; padding:3px 10px;}
  9.   a#nxt:hover, a#nxt.active{ color:#FF0000; text-decoration:none;}
  10.  
  11.   #roundList{ font-size:12px; color:#000000; position:absolute; top:190px; left:10px;} 
  12.   #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;}
  13.   #roundList a:hover, #roundList a.active{ background:#FF0000; border:1px #ff0000 solid;}

simple jquery slider with next previous buttons -- w3web.net

 

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

Further post that would you like to learn in Salesforce

 
 

 

 

FAQ (Frequently Asked Questions)

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

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

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



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment