-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPinScroll-0.1.min.js
More file actions
2 lines (2 loc) · 2.06 KB
/
PinScroll-0.1.min.js
File metadata and controls
2 lines (2 loc) · 2.06 KB
1
2
// PinScroll v0.1 - Copyright (c) 2010, Jarvis Badgley - chiper[at]chipersoft[dot]com - Distributed under MIT license
var PinScroll=Class.create({initialize:function(c,b){var a=this;a.options={pinTrayTag:"ul",pinTrayID:"Pintray",pinTrayPadding:10,pinTrayPaddingTop:undefined,pinTrayPaddingBottom:undefined,pinTag:"li",loadDelay:1000,scrollDuration:0.5,fadeInDuration:1};Object.extend(a.options,b||{});Event.observe(window,"resize",a.update.bind(a));a.pintray=(new Element(this.options.pinTrayTag,{id:a.options.pinTrayID})).hide();a.pins=$A();$H(c).each(function(d){var e=null;if(d.value){if(d.value.image){e=new Element("img",{src:d.value.image});}if(d.value.selector){e=$$(d.value.selector).first();}if(d.value.element){e=$(d.value.element);}if(e){e.pinUsed=e.pinUsed||0;}}$$(d.key).each(function(f){if(f.anchorPin){f.anchorPin.remove();}if(!e){return;}var g=new Element(a.options.pinTag);g.pinAnchor=f;f.anchorPin=g;if(!e.pinUsed++){g.insert(e.show());}else{g.insert(e.clone(true));}g.observe("click",function(j){var k=parseInt(this.pinAnchor.getStyle("margin-top")||0);if(isNaN(k)){k=0;}try{Effect.ScrollTo(this.pinAnchor,{duration:a.options.scrollDuration,offset:-k/2});}catch(l){var h=document.viewport.getScrollOffsets(),i=this.pinAnchor.cumulativeOffset();scrollTo(h.left,i[1]-k/2);}});a.pintray.insert(g);a.pins.push({anchor:f,pin:g});});});setTimeout(function(){if(a.pintray.appear){a.pintray.appear({duration:a.options.fadeInDuration,afterSetup:a.update.bind(a)});}else{a.pintray.show();a.update();}},a.options.loadDelay);document.body.appendChild(this.pintray);},update:function(){var a=document.viewport.getHeight(),c=Math.max(document.body.getHeight(),a);var b=this;this.pins.each(function(g){g.anchor.visible()&&g.anchor.parentNode?g.pin.show():g.pin.hide();var d=g.anchor.cumulativeOffset(),e=g.pin.getHeight()/2,f=((d[1]/c)*a)-e;f=Math.max(b.options.pinTrayPaddingTop!=undefined?b.options.pinTrayPaddingTop:b.options.pinTrayPadding,Math.min(f,a-e-(b.options.pinTrayPaddingBottom!=undefined?b.options.pinTrayPaddingBottom:b.options.pinTrayPadding)*2)).round();g.pin.setStyle({top:f+"px"});});}});