sliders.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var sliderMain = document.getElementsByClassName("slider")[0];
  2. var divs = sliderMain.getElementsByClassName("slide-menu");
  3. var next = document.getElementById("next");
  4. var prev = document.getElementById("prev");
  5. var timer = setInterval(slider, 3000);
  6. var flagForT = true;
  7. function startTime() {
  8. timer = setInterval(slider, 3000);
  9. flagForT = true
  10. }
  11. function pauseTimer() {
  12. if (flagForT) {
  13. clearInterval(timer);
  14. setTimeout(startTime, 5000);
  15. flagForT = false;
  16. }
  17. }
  18. next.onclick = function () {
  19. pauseTimer();
  20. return slider();
  21. };
  22. prev.onclick = function () {
  23. pauseTimer();
  24. return slider(true);
  25. };
  26. // default direction to right. If you want to change on left you can write true in variable "changeOfDirection"
  27. function slider(changeOfDirection) {
  28. var active = sliderMain.getElementsByClassName("active");
  29. var nextElem;
  30. if (changeOfDirection) {
  31. nextElem = active[0].previousElementSibling;
  32. } else {
  33. nextElem = active[0].nextElementSibling;
  34. }
  35. var indexOf = [].indexOf;
  36. if (nextElem == null || !nextElem.classList.contains("slide-menu")) {
  37. nextElem = divs[divs.length - 1 - indexOf.call(divs, active[0])];
  38. }
  39. active[0].classList.remove("active");
  40. nextElem.classList.add("active");
  41. }
  42. /*Second slider for partner*/
  43. var sliderPartner = document.getElementsByClassName("multtiple-slider")[0];
  44. var divsPartner = sliderPartner.getElementsByClassName("slide-item");
  45. var timer2 = setInterval(nextPartner, 3000);
  46. function nextPartner() {
  47. var activElements = sliderPartner.getElementsByClassName("acitve");
  48. var lastElemen = divsPartner[divsPartner.length - 1];
  49. activElements[activElements.length - 1].classList.remove("acitve");
  50. sliderPartner.removeChild(lastElemen);
  51. lastElemen.classList.add("acitve");
  52. sliderPartner.insertBefore(lastElemen, activElements[0]);
  53. }
  54. var activDiv = document.getElementsByClassName("comment")[0];
  55. var divs_target = document.getElementsByClassName("comment");
  56. function createBtn(i) {
  57. var btn = document.createElement("input");
  58. btn.setAttribute("type", "button");
  59. btn.setAttribute("name", i);
  60. btn.className = 'ctrl';
  61. return btn;
  62. }
  63. function countDiv(idNameWhen) {
  64. var target_div = document.getElementsByClassName(idNameWhen)[0];
  65. for (var i = 0; i < divs_target.length; i++) {
  66. var btn = createBtn(i);
  67. target_div.appendChild(btn);
  68. btn.addEventListener("click", normal);
  69. }
  70. }
  71. function normal(e) {
  72. var div = divs_target[e.target.name];
  73. activDiv.classList.remove("active");
  74. div.classList.add("active");
  75. activDiv = div;
  76. };
  77. countDiv("points-ctrl");