javascript - Slider is not rendered properly -


i want simple slider based on margin-left css property, looks result not rendered between partial margin-left increments. wrong code?

https://jsfiddle.net/1utkr6et/

html:

<div class="main-padding">     <div id="wrapper-slider">         <div class="item-slider item-slider1"></div>         <div class="item-slider item-slider2"></div>         <div class="item-slider item-slider3"></div>     </div> </div> 

css:

* {     border: 0;     margin: 0;     padding: 0;     outline: 0; }  {     text-decoration: none;     color: inherit; }  body {     font-size: 62.5%; }  ul, ol {     list-style-type: none; }  .main-padding {     padding: 20px; }   #wrapper-slider {     height: 200px;     position: relative;     overflow: hidden; }  .item-slider {     width: 100%;     float: left;     height: 100%; }  .item-slider1 {     background-color: red; }  .item-slider2 {     background-color: blue; }  .item-slider3 {     background-color: yellow; } 

js(jquery):

$(function () {      var item = ".item-slider";     var next = 1;     setinterval(function() {         $(item + next).animate({"marginleft": "-100%"}, 1000);         next++;     }, 2000);  }); 

the main problem slider defining elements of slider float. have made few changes in code make work properly.

css:

.item-slider {     position: absolute;     left: 100%;     width: 100%;     height: 100%; } 

javascript:

$(function () {      var item = ".item-slider";     var next = 1;     var current;     setinterval(function() {         if(next === 1){             prev = $(item + 3);         }else{             prev = $(item + (next - 1));         }         current = $(item + next);         current.css({"left": "100%"});         current.animate({"left": "0"}, 1000);         prev.animate({"left": "-100%"}, 1000);         if(next === 3){             next = 1;         }else{             next++;         }     }, 2000);  }); 

fiddle: https://jsfiddle.net/lmgonzalves/1utkr6et/5/


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -