-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.v1.min.js
1 lines (1 loc) · 3.29 KB
/
stack.v1.min.js
1
function stack(){function e(e,t){var n=b[0][t],a=e.sourceEvent=d3.event;try{d3.event=e,y[e.type].call(n,n.__data__,t)}finally{d3.event=a}}function t(){var e=20;s=d[1]/d[0]*innerWidth,l=innerHeight,b.style("height",s+"px").style("box-shadow","0 4px 4px rgba(0,0,0,.3)").filter(function(e,t){return g-1>t}).style("margin-bottom",e+"px"),m.style("font-size",innerWidth/d[0]*r+"px")}function n(){if(s)var e=f;s=d[1]/d[0]*innerWidth,l=innerHeight,k.style("top",(l-s)/2+"px").style("height",s+"px"),w.style("top",function(e){return(e+(1-v)/2)*l+"px"}).style("height",l*v+"px"),m.style("font-size",innerWidth/d[0]*r+"px").style("height",l*g+"px"),isNaN(e)||scrollTo(0,(f=e)*l)}function a(){var t=pageYOffset/l,n=Math.max(0,Math.min(g-1,Math.floor(t)));h!==n&&(n===h+1?(z.style("display","none"),z=M,M=d3.select(b[0][n+1]),e({type:"deactivate"},h),g-1>n&&e({type:"activate"},n+1)):n===h-1?(M.style("display","none"),M=z,z=d3.select(b[0][n]),g-1>h&&e({type:"deactivate"},h+1),e({type:"activate"},n)):(z.style("display","none"),M.style("display","none"),z=d3.select(b[0][n]),M=d3.select(b[0][n+1]),isNaN(h)||(e({type:"deactivate"},h+1),e({type:"deactivate"},h)),e({type:"activate"},n),g-1>n&&e({type:"activate"},n+1)),z.style("display","block").style("opacity",1),M.style("display","block"),h=n),t-n>(1-v)/2?M.style("display","block").style("opacity",Math.min(1,(t-n-(1-v)/2)/v)):M.style("display","none"),e({type:"scroll",offset:f=t},h)}function i(){var e;switch(d3.event.keyCode){case 39:if(d3.event.metaKey)return;case 40:case 34:e=d3.event.metaKey?1/0:1;break;case 37:if(d3.event.metaKey)return;case 38:case 33:e=d3.event.metaKey?-1/0:-1;break;case 32:e=d3.event.shiftKey?-1:1;break;default:return}var t=isNaN(o)?f:o;o=Math.max(0,Math.min(g-1,(e>0?Math.floor(t+(1-v)/2):Math.ceil(t-(1-v)/2))+e)),d3.select(document.documentElement).interrupt().transition().duration(500).tween("scroll",function(){var e=d3.interpolateNumber(pageYOffset,o*l);return function(t){scrollTo(0,e(t))}}).each("end",function(){o=0/0}),d3.event.preventDefault()}var s,l,o,c={},d=[1280,720],r=32,y=d3.dispatch("scroll","activate","deactivate"),p="ontouchstart"in document,u=p?t:n,h=0/0,f=0,v=1/6,b=d3.selectAll("section").style("box-sizing","border-box").style("line-height","1.35em"),g=b.size(),m=d3.select("body").style("margin",0).style("padding",0).style("background","#333");if(p)b.style("position","relative"),d3.select(window).on("resize.stack",u).each(u);else{var x=d3.select("body").insert("div","section").style("box-shadow","0 8px 16px rgba(0,0,0,.3)");b.style("display","none");var k=d3.selectAll(b[0].concat(x.node())).style("position","fixed").style("left",0).style("top",0).style("width","100%"),w=d3.select("body").append("div").attr("class","indicator").selectAll("div").data(d3.range(b.size())).enter().append("div").style("position","absolute").style("left",0).style("width","3px").style("background","linear-gradient(to top,black,white)"),z=d3.select(b[0][0]).style("display","block"),M=d3.select(b[0][1]).style("display","block");d3.select(window).on("resize.stack",u).on("scroll.stack",a).on("keydown.stack",i).each(u),d3.timer(function(){return a(),!0})}return c.size=function(e){return arguments.length?(d=[+e[0],+e[1]],u(),c):d},c.scrollRatio=function(e){return arguments.length?(v=+e,u(),c):v},c.fontSize=function(e){return arguments.length?(r=+e,u(),c):r},d3.rebind(c,y,"on"),c}