Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. var autoAdjustHeight = true;
  2.  
  3. $('nav a').on('mousedown', function(e){
  4. e.preventDefault();
  5. var goTo = $(this).parent().index();
  6. swipegoryUpdate(goTo);
  7. });
  8. $("ul.panes").swipe({
  9. swipeStatus:function(event, phase, direction, distance, duration, fingerCount) {
  10. var translateString = 'translate3d(0px, 0px, 0px)';
  11. var transitionDuration = $('nav li.cur').css('transitionDuration');
  12. var speed = transitionDuration;
  13.  
  14. if(phase == 'move') {
  15. speed = '0ms';
  16. if(direction == 'left') {
  17. translateString = 'translate3d(-' + distance + 'px, 0px, 0px)';
  18. $('.panes li.cur').css('marginLeft', '-'+ distance +'px');
  19. }
  20. else if(direction == 'right') {
  21. translateString = 'translate3d(' + distance + 'px, 0px, 0px)';
  22. $('.panes li.cur').css('marginLeft', distance +'px');
  23. }
  24. $('nav li.cur').css({
  25. transitionDuration: speed,
  26. transform: translateString
  27. });
  28.  
  29. }
  30. else if (phase == 'end') {
  31. var marginLeft = $('nav li.cur').css('marginLeft');
  32. $('nav li.cur').attr('style', '').css('marginLeft', marginLeft);
  33. $('.panes li.cur').attr('style', '');
  34. }
  35. },
  36. swipeLeft:function(event, direction, distance, duration, fingerCount) {
  37. var goTo = $('nav li.cur').index();
  38. goTo++;
  39. swipegoryUpdate(goTo);
  40. },
  41. swipeRight:function(event, direction, distance, duration, fingerCount) {
  42. //This only fires when the user swipes left
  43. var goTo = $('nav li.cur').index();
  44. goTo--;
  45. swipegoryUpdate(goTo);
  46. },
  47. threshold: 50,
  48. triggerOnTouchEnd: false,
  49. allowPageScroll: "vertical",
  50. excludedElements: "button, input, select, textarea, .noSwipe"
  51. });
  52.  
  53. $(window).load(function() {
  54. swipegoryUpdate(1);
  55. });
  56.  
  57. function swipegoryUpdate(goTo) {
  58. var listItems = $('nav li');
  59. var panes = $('.panes');
  60. var prev = goTo - 1;
  61. var next = goTo + 1;
  62. if(goTo >= 0 && goTo < listItems.length) {
  63. listItems.removeClass('prev').removeClass('cur').removeClass('next').removeClass('before').removeClass('after');
  64. $('li', panes).removeClass('prev').removeClass('cur').removeClass('next').removeClass('before').removeClass('after');
  65.  
  66. listItems.each(function(i) {
  67. var li = $(this);
  68. var pane = $('li:eq('+i+')', panes);
  69.  
  70. li.attr('style', '');
  71.  
  72. if(i == prev) {
  73. li.addClass('prev');
  74. li.css('margin-left', '0');
  75. pane.addClass('prev');
  76. }
  77. else if(i == next) {
  78. li.addClass('next');
  79. li.css('margin-left', '-' + li.outerWidth() + 'px');
  80. pane.addClass('next');
  81. }
  82. else if(i < goTo) {
  83. li.addClass('before');
  84. li.css('margin-left', '-' + li.outerWidth() + 'px');
  85. pane.addClass('before');
  86. }
  87. else if(i == goTo) {
  88. li.addClass('cur');
  89. var marginLeft = li.outerWidth() / 2;
  90.  
  91. li.css('margin-left', '-' + marginLeft + 'px');
  92. pane.addClass('cur');
  93.  
  94. if(autoAdjustHeight == true) {
  95. $('.swipegory').css('height', pane.outerHeight() + li.outerHeight());
  96. }
  97.  
  98. }
  99. else if(i > goTo) {
  100. li.addClass('after');
  101. li.css('margin-left', '0');
  102. pane.addClass('after');
  103. }
  104. });
  105. }
  106. }
  107.  
  108. if (!("ontouchstart" in document.documentElement)) {
  109. document.documentElement.className += " no-touch";
  110. }
Add Comment
Please, Sign In to add comment