Last active
October 12, 2015 03:29
-
-
Save mattmazzola/874f0de00a005fc2d239 to your computer and use it in GitHub Desktop.
sd-cycle
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', | |
things: [ | |
{ id: 1, name: 'a' }, | |
{ id: 2, name: 'b' }, | |
{ id: 3, name: 'c' } | |
] | |
}); |
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'; | |
const { | |
computed | |
} = Ember; | |
export default Ember.Component.extend({ | |
currentItemIndex: 0, | |
height: 50, | |
transition: true, | |
circularItems: computed('items', function() { | |
return this.get('items').concat(this.get('items').objectAt(0)) | |
}), | |
currentItem: computed('currentItemIndex', function() { | |
return this.get('items').objectAt(this.get('currentItemIndex')); | |
}), | |
currentOffset: computed('currentItemIndex', function() { | |
return this.get('currentItemIndex') * this.get('height'); | |
}), | |
inlineStyleHeight: computed('height', function() { | |
const string = `height: ${this.get('height')}px`; | |
console.log(`string: ${string}`); | |
return new Ember.Handlebars.SafeString(`height: ${this.get('height')}px`); | |
}), | |
inlineStyleTop: computed('currentOffset', function() { | |
return new Ember.Handlebars.SafeString(`top: -${this.get('currentOffset')}px`); | |
}), | |
actions: { | |
updateIndex() { | |
const index = this.get('currentItemIndex'); | |
const nextIndex = (index + 1) % this.get('circularItems.length'); | |
if(nextIndex === 0) { | |
this.set('transition', false); | |
this.set('currentItemIndex', nextIndex); | |
Ember.run.next(this, function () { | |
this.set('transition', true); | |
this.set('currentItemIndex', nextIndex + 1); | |
}); | |
} | |
else { | |
this.set('transition', true); | |
this.set('currentItemIndex', nextIndex); | |
} | |
this.set('currentItemIndex', nextIndex); | |
} | |
} | |
}); |
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; | |
} | |
.sd-cycle { | |
overflow: hidden; | |
position: relative; | |
border: 1px solid blue; | |
} | |
.sd-cycle__items--transition { | |
transition: top 1s ease-out; | |
} | |
.sd-cycle__items { | |
position: absolute; | |
width: 100%; | |
} | |
.sd-cycle__item { | |
background: #ececec | |
} |
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.4.11", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment