Forked from miguelcobain/components.in-viewport.js
Last active
December 14, 2016 15:15
-
-
Save HenryVonfire/92037fd9d09fae30f1effb265dd79501 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', | |
actions:{ | |
getHeight(){ | |
let ele = Ember.$('.scrollable'); | |
this.set('test', ele.height()); | |
} | |
} | |
}); |
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; | |
right: 0; | |
bottom: 0; | |
overflow-x: auto; | |
background-color: grey; | |
border:5px solid green; | |
} | |
.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