slider-noAnimation.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var arrowLeft = document.getElementById("arrow-left");
  2. var arrowRight = document.getElementById("arrow-right");
  3. var slides = document.querySelector(".slides");
  4. var i = 0;
  5. arrowRight.onclick = function(){
  6. if(i === slides.children.length - 1){
  7. slides.children[i].style.opacity = "0";
  8. slides.children[i].style.zIndex = "0";
  9. slides.children[0].style.opacity = "1";
  10. slides.children[0].style.zIndex = "1";
  11. i = 0;
  12. }
  13. else{
  14. slides.children[i].style.opacity = "0";
  15. slides.children[i].style.zIndex = "0";
  16. slides.children[i + 1].style.opacity = "1";
  17. slides.children[i + 1].style.zIndex = "1";
  18. i++;
  19. }
  20. }
  21. arrowLeft.onclick = function(){
  22. if(i === 0){
  23. slides.children[0].style.opacity = "0";
  24. slides.children[0].style.zIndex = "0";
  25. slides.children[slides.children.length - 1].style.opacity = "1";
  26. slides.children[slides.children.length - 1].style.zIndex = "1";
  27. i = slides.children.length - 1;
  28. }
  29. else{
  30. slides.children[i].style.opacity = "0";
  31. slides.children[i].style.zIndex = "0";
  32. slides.children[i - 1].style.opacity = "1";
  33. slides.children[i - 1].style.zIndex = "1";
  34. i--;
  35. }
  36. }
  37. for (var k = 0; k < slides.children.length; k++) {
  38. var dotsContainer = document.createElement("div");
  39. dotsContainer.setAttribute("class", "dots-container");
  40. dotsContainer.setAttribute("style","margin-top: 50px; ");
  41. slides.children[k].appendChild(dotsContainer);
  42. for (var j = 0; j < slides.children.length; j++) {
  43. var dot = document.createElement("div");
  44. dot.setAttribute("name",j)
  45. dot.onclick = function(){
  46. if(!this.getAttribute("class") ){
  47. slides.children[i].style.opacity = "0";
  48. slides.children[i].style.zIndex = "0";
  49. i = +this.getAttribute("name");
  50. slides.children[i].style.opacity = "1";
  51. slides.children[i].style.zIndex = "1";
  52. }
  53. }
  54. if(j === k){
  55. dot.setAttribute("style","border-radius: 50%; margin-right: 5px; border:1px solid #00e0d0; background-color: #00e0d0; width: 10px; height: 10px; display: inline-block; ");
  56. dot.setAttribute("class", "active");
  57. slides.children[k].querySelector(".dots-container").appendChild(dot);
  58. }
  59. else{
  60. dot.setAttribute("style","border-radius: 50%; margin-right: 5px; border:1px solid #fff; width: 10px; height: 10px; display: inline-block; ");
  61. slides.children[k].querySelector(".dots-container").appendChild(dot);
  62. }
  63. }
  64. }