Last active
December 14, 2016 13:31
-
-
Save miguelcobain/c990d4eaa501414c083cc4e3d1b5b075 to your computer and use it in GitHub Desktop.
ember-sticky
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import InViewportMixin from 'ember-in-viewport'; | |
const { Component, computed, String: { htmlSafe } } = Ember; | |
function outerHeight(el) { | |
var height = el.offsetHeight; | |
var style = getComputedStyle(el); | |
height += parseInt(style.marginTop) + parseInt(style.marginBottom); | |
return height; | |
} | |
export default Component.extend(InViewportMixin, { | |
classNames: ['sticky-wrapper'], | |
attributeBindings: ['style'], | |
style: computed('wrapperHeight', function() { | |
let wrapperHeight = this.get('wrapperHeight'); | |
return wrapperHeight ? htmlSafe(`height: ${wrapperHeight}px;`) : null; | |
}), | |
init() { | |
this._super(...arguments); | |
this.set('viewportSpy', true); | |
}, | |
didEnterViewport() { | |
console.log('entered'); | |
this.set('fixed', false); | |
this.set('wrapperHeight', null); | |
}, | |
didExitViewport() { | |
console.log('exited'); | |
this.set('wrapperHeight', outerHeight(this.element.children[0])); | |
this.set('fixed', true); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.scrollable { | |
position: absolute; | |
top: 0; | |
left: 0; | |
bottom: 0; | |
right: 0; | |
overflow-x: auto; | |
background-color: grey; | |
} | |
.header { | |
height: 50px; | |
background-color: yellow; | |
padding: 10px; | |
} | |
.secondary-header { | |
height: 50px; | |
background-color: red; | |
padding: 10px; | |
} | |
.fixed { | |
position: fixed; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.body { | |
padding: 10px; | |
height: 1000px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.6", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.9.0", | |
"ember-data": "2.9.0", | |
"ember-template-compiler": "2.9.0", | |
"ember-testing": "2.9.0" | |
}, | |
"addons": { | |
"ember-in-viewport": "2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment