jquery - Creating bookmarks of titles while scroll -


im making bookmarks on scroll. concept: when scroll , title reaches top of screen script adds left appropriative bookmark. im using tweenmax add animation action. problem when scroll , forth around removed bookmarks not alwayes added left, throught 2-4 scrolls around it. can understand why. ideas? codepen here. , code itself:

$(window).scroll(function () {     $('h2').each(function(i){         var elementontop = $(this).offset().top,             winsize = $(window).scrolltop(),             title = $(this).text(),             textid = 'title-' + i++ ,             linkto = $(this).attr('id');          if (winsize > elementontop) {             if ($('.marks a:contains('+ title + ')').length == 0) {                 $('.marks').append('<a href="#' + linkto + '" id="' + textid + '">' + title + '</a>');                 tweenmax.from('#'+textid, 1, {y: -20, opacity: 0, ease:elastic.easeout, force3d:false}, 0.2);             }          } else {             tweenmax.to('#'+textid, 1, {y: -20, opacity: 0, ease:back.easeout, force3d:false,  oncomplete:function(){(this.target).remove()}});          }     }) }); 


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -