]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/unlimited_pizza/melty_cheese.js
9c8a1e8ae201fc21fafa497127da6c1342f2fec3
3 Class(UnlimitedPizza
, "MeltyCheese").inherits(Widget
)({
5 min : 60, // min height of the element
6 max : 480, // max height of the element
7 minThreshold : 200, // distance from bottom before we start
8 maxThreshold : 500, // distance from bottom before we stop
11 init : function (config
) {
12 Widget
.prototype.init
.call(this, config
)
14 this._bindInternalEvents();
17 _bindInternalEvents : function bindInternalEvents() {
18 this.bind('activate', this._onActivate
.bind(this));
19 this.bind('deactivate', this._onDeactivate
.bind(this));
22 _onActivate : function _activate() {
23 // If this is the first time activating it... then load
29 _onDeactivate : function _deactivate() {
36 _load : function _load() {
39 this.image
= this.element
.find('img')
42 _unload : function _unload() {
47 _bindEvents : function bindEvents() {
48 $(window
).on('scroll', this._onScroll
.bind(this));
49 $(window
).on('resize', this._onScroll
.bind(this));
52 _unbindEvents : function unbindEvents() {
53 $(window
).off('scroll');
54 $(window
).off('resize');
57 /* Listeners beyond */
59 _onScroll : function onScroll() {
60 var documentTop
, documentBottom
, elementTop
, diff
, height
;
63 documentTop
= $(window
).scrollTop();
64 documentBottom
= documentTop
+ $(window
).height();
65 elementTop
= this.element
.offset().top
;
66 diff
= documentBottom
- elementTop
;
68 this.max
= this.image
.height();
69 this.min
= this.max
/ 10;
71 diff
-= this.minThreshold
;
73 height
= diff
* this.max
/ this.maxThreshold
;
75 if (height
< this.min
) {
79 if (height
> this.max
) {
83 console
.log("I, ", this.name
, "should be ", height
);
85 this.element
.height(height
);