]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/unlimited_pizza/melty_cheese.js
1059a6053a6c2662551b5a34d6f334b8805b1866
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')
43 _unload : function _unload() {
48 _bindEvents : function bindEvents() {
49 $(window
).on('scroll', this._onScroll
.bind(this));
50 $(window
).on('resize', this._onScroll
.bind(this));
53 _unbindEvents : function unbindEvents() {
54 $(window
).off('scroll');
55 $(window
).off('resize');
58 /* Listeners beyond */
60 _onScroll : function onScroll() {
61 var documentTop
, documentBottom
, elementTop
, diff
, height
;
64 documentTop
= $(window
).scrollTop();
65 documentBottom
= documentTop
+ $(window
).height();
66 elementTop
= this.element
.offset().top
;
67 diff
= documentBottom
- elementTop
;
69 this.max
= this.image
.height();
70 this.min
= this.max
/ 10;
72 diff
-= this.minThreshold
;
74 height
= diff
* this.max
/ this.maxThreshold
;
76 if (height
< this.min
) {
80 if (height
> this.max
) {
84 this.element
.height(height
);