diff --git a/index.html b/index.html index ca5fe22..ab962d6 100644 --- a/index.html +++ b/index.html @@ -57,8 +57,14 @@ var Time = Jobs:[], Stamp:false, Queue:false, + Loop:false, Add:function(inJob) { + if(Time.Loop) + { + console.log("cannot modify queue while processing"); + return; + } if(!Time.Queue) { window.requestAnimationFrame(Time.Update); @@ -66,6 +72,19 @@ var Time = Time.Queue = true; Time.Jobs.push(inJob); }, + Remove:function(inJob) + { + if(Time.Loop) + { + console.log("cannot modify queue while processing"); + return; + } + var index = Time.Jobs.indexOf(inJob); + if(index > -1) + { + Time.Jobs.splice(index, 1); + } + }, Update:function(inTimestamp) { var delta; @@ -78,14 +97,16 @@ var Time = delta = inTimestamp - Time.Stamp; Time.Stamp = inTimestamp; + Time.Loop = true; for(i=0; i 0) { @@ -99,7 +120,7 @@ var Time = } }; -function JobConic(inFrom, inRange, inDuration, inHandler) +function JobDuration(inDuration, inHandler, inDone) { var timeCurrent = 0; var timeLimit = inDuration*1000; @@ -109,21 +130,28 @@ function JobConic(inFrom, inRange, inDuration, inHandler) { timeCurrent += inDelta; timeMaxed = timeCurrent > timeLimit; - if(timeMaxed){ timeCurrent = timeLimit; } - timeRelative = timeCurrent / timeLimit; - inHandler(inFrom + inRange*Math.sqrt(1 - Math.pow(1-(timeRelative), 2))); - return !timeMaxed; + if(timeMaxed) + { + inHandler(1); + inDone(); + return false; + } + return inHandler(timeCurrent / timeLimit); }; } document.querySelector("nav").addEventListener("click", function(inEvent) { - var href = inEvent.target.getAttribute("href"); - var html = document.querySelector("html"); - var goal = document.querySelector(href).getBoundingClientRect().top; - - Time.Add( JobConic(html.scrollTop, goal, 0.4, function(inOutput){ html.scrollTop = inOutput; } ) ); + var domHtml = document.querySelector("html"); + var domGoal = document.querySelector(inEvent.target.getAttribute("href")); + var posStart = domHtml.scrollTop - 200; + var posRange = domGoal.getBoundingClientRect().top; + var evtTick = function(inProgress){ domHtml.scrollTop = posStart + posRange*Math.sqrt(1 - Math.pow(1-(inProgress), 2)); }; + var evtDone = function(){ Spy.Resume(); }; + + Spy.Suspend(); + Time.Add( JobDuration(0.4, evtTick, evtDone) ); inEvent.preventDefault(); }); @@ -134,11 +162,23 @@ var Spy = Attribute:"data-spy", Members:[], Defaults:[0, 1, 0, 1], + Disabled:false, + Suspend:function() + { + Spy.Disabled = true; + }, + Resume:function() + { + Spy.Disabled = false; + Spy.UpdateAll(); + }, UpdateAll:function() { var i, member, aabb, top, bottom, left, right; var visible; + if(Spy.Disabled){ return; } + for(i=0; i