You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.8 KiB

2 years ago
  1. $(document).ready(function () {
  2. $(document).ready(function () {
  3. // Gets total amount of slides
  4. var count = $(".slide").length;
  5. // Sets the slide-container and individual slide size
  6. $(".slide-container").css({ "width": 100 * count + "%", 'margin-left': '-400%' });
  7. $(".slide").css("width", $(".slide-container").width() / count + "px");
  8. var rollLeft = function () {
  9. $(".slide-container").animate({ marginLeft: "-500%" }, 400, "linear", function () {
  10. $(".slide-container").css({ marginLeft: "-400%" });
  11. $(".slide-container .slide:first").remove().clone(true).appendTo(".slide-container");
  12. });
  13. },
  14. rollRight = function () {
  15. $(".slide-container").animate({ marginLeft: "-300%" }, 400, "linear", function () {
  16. $(".slide-container").css({ marginLeft: "-400%" });
  17. $(".slide-container .slide:last").remove().clone(true).prependTo(".slide-container");
  18. });
  19. },
  20. startRoll = setInterval(rollLeft, 7000);
  21. $('.prev').click(function (e) {
  22. e.preventDefault();
  23. clearInterval(startRoll);
  24. rollRight();
  25. startRoll = setInterval(rollLeft, 7000);
  26. });
  27. $('.next').click(function (e) {
  28. e.preventDefault();
  29. clearInterval(startRoll);
  30. rollLeft();
  31. startRoll = setInterval(rollLeft, 7000);
  32. });
  33. $(".slider-box").on("swipeleft", function () {
  34. $(".next").click();
  35. });
  36. $(".slider-box").on("swiperight", function () {
  37. $(".prev").click();
  38. });
  39. $(window).resize(function () {
  40. $(".slide").css("width", $(".slide-container").width() / count + "px");
  41. });
  42. });
  43. });