Advertisement
Guest User

Untitled

a guest
Nov 30th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /*--------------------------------------------------------------
  2. ## Anchor skipper
  3. --------------------------------------------------------------*/
  4. var pagePosition = 0,
  5. sectionsSelector = '.jumptarget',
  6. $scrollItems = $(sectionsSelector),
  7. offsetTolerance = 30,
  8. pageMaxPosition = $scrollItems.length - 1;
  9.  
  10. $scrollItems.each(function(index,ele) { $(ele).attr("debog",index).data("pos",index); });
  11.  
  12. $(window).bind('scroll load',upPos);
  13.  
  14. $('#arrow a').click(function(e){
  15.  
  16. if ($(this).hasClass('next') && pagePosition+1 <= pageMaxPosition) {
  17. pagePosition++;
  18. $('html, body').stop().animate({
  19. scrollTop: $scrollItems.eq(pagePosition).offset().top
  20. }, 800);
  21. }
  22.  
  23. if ($(this).hasClass('backtop') && pagePosition-1 >= 0) {
  24. pagePosition = 0;
  25. $('html, body').stop().animate({
  26. scrollTop: 0
  27. }, 800);
  28. return false;
  29. }
  30. });
  31.  
  32. function upPos(){
  33. var fromTop = $(this).scrollTop();
  34. var $cur = null;
  35. var totalCur = $('.jumptarget').length-1;
  36.  
  37.  
  38. $scrollItems.each(function(index,ele){
  39. if ($(ele).offset().top < fromTop + offsetTolerance) $cur = $(ele);
  40. });
  41.  
  42. if ($cur != null && pagePosition != $cur.data('pos')) {
  43. pagePosition = $cur.data('pos');
  44.  
  45. var current = $($cur).attr("debog");
  46.  
  47. if ( current == totalCur ) {
  48. $('#arrow a').removeClass('next');
  49. $('#arrow a').addClass('backtop').text('🡅');
  50. } else {
  51. $('#arrow a').addClass('next').text('🡇');
  52. $('#arrow a').removeClass('backtop');
  53. };
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement