Description
We often have a requirement for the slider in our Web pages and at that time, we look for the slider plugin, which is available in the thousands on the internet, but why can't we create our own as it's not so difficult to create? Let's create our own, simple short slider control, which is easy to understand.
We often have a requirement for the slider in our Web pages and at that time, we look for the slider plugin, which is available in the thousands on the internet, but why can't we create our own as it's not so difficult to create? Let's create our own, simple short slider control, which is easy to understand.
CSS
JavaScript
- <style>
- .active
- {
- width: 100%;
- height: 300px;
- }
- .inactive {
- display: none;
- }
- </style>
- <script src="http://code.jquery.com/jquery-1.8.0.min.js" type="text/javascript"></script>
- <script>
- $(document).ready(function() {
- setInterval(function() {
- AddActive_AndInactiveClass();
- }, 3000);
- });
- function AddActive_AndInactiveClass() {
- var currentActiveImage = $("img.active").attr("id");
- $("#" + currentActiveImage).removeClass("active");
- $("#" + currentActiveImage).addClass("inactive");
- $("#" + currentActiveImage).next().removeClass("inactive");
- $("#" + currentActiveImage).next().addClass("active");
- //Check if this is the last image, then set first image as active
- var CheckIfIsThisLastImage = $("#" + currentActiveImage).next().length;
- if (CheckIfIsThisLastImage == 0) {
- $('#divslider img').first().removeClass('inactive');
- $('#divslider img').first().addClass('active');
- }
- }
- </script>


kalu singh raoPosted Jul 18, 2016, 2:06 AM
Nice...