Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*--------------------------------------------------------------
- ## Anchor skipper
- --------------------------------------------------------------*/
- var pagePosition = 0,
- sectionsSelector = '.jumptarget',
- $scrollItems = $(sectionsSelector),
- offsetTolerance = 30,
- pageMaxPosition = $scrollItems.length - 1;
- $scrollItems.each(function(index,ele) { $(ele).attr("debog",index).data("pos",index); });
- $(window).bind('scroll load',upPos);
- $('#arrow a').click(function(e){
- if ($(this).hasClass('next') && pagePosition+1 <= pageMaxPosition) {
- pagePosition++;
- $('html, body').stop().animate({
- scrollTop: $scrollItems.eq(pagePosition).offset().top
- }, 800);
- }
- if ($(this).hasClass('backtop') && pagePosition-1 >= 0) {
- pagePosition = 0;
- $('html, body').stop().animate({
- scrollTop: 0
- }, 800);
- return false;
- }
- });
- function upPos(){
- var fromTop = $(this).scrollTop();
- var $cur = null;
- var totalCur = $('.jumptarget').length-1;
- $scrollItems.each(function(index,ele){
- if ($(ele).offset().top < fromTop + offsetTolerance) $cur = $(ele);
- });
- if ($cur != null && pagePosition != $cur.data('pos')) {
- pagePosition = $cur.data('pos');
- var current = $($cur).attr("debog");
- if ( current == totalCur ) {
- $('#arrow a').removeClass('next');
- $('#arrow a').addClass('backtop').text('🡅');
- } else {
- $('#arrow a').addClass('next').text('🡇');
- $('#arrow a').removeClass('backtop');
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement