Skip to content

Instantly share code, notes, and snippets.

@vitch
Created August 28, 2015 13:37
Show Gist options
  • Save vitch/bad10a848dda43c289ac to your computer and use it in GitHub Desktop.
Save vitch/bad10a848dda43c289ac to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
sections: [1,2,3,4,5],
currentSection: 0,
isLastSection: Ember.computed('currentSection', function() {
return this.get('currentSection') === this.get('sections.length') - 1;
}),
sectionClassName: Ember.computed('currentSection', function() {
return 'section-' + this.get('currentSection');
}),
actions: {
gotoNext() {
this.incrementProperty('currentSection');
},
gotoSection(section) {
var sectionIndex = this.get('sections').indexOf(section);
this.set('currentSection', sectionIndex);
}
}
});
<h1>Nav demo</h1>
<p>
{{#if isLastSection}}
&nbsp;
{{else}}
<a href="#" {{action 'gotoNext'}}>Next</a>
{{/if}}
</p>
<ul class="sections-nav {{sectionClassName}}">
{{#each sections as |section|}}
<li {{action 'gotoSection' section}}></li>
{{/each}}
<li class="active-marker"></li>
</ul>
<br>
<br>
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.sections-nav {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
.sections-nav li {
border-radius: 50%;
background: #ccc;
cursor: pointer;
display: inline-block;
height: 10px;
margin: 0 5px;
width: 10px;
}
.sections-nav li.active-marker {
background: #999;
position: absolute;
left: 0;
pointer-events: none;
top: 5px;
transition: left .3s ease-in-out;
}
.section-1 li.active-marker {
left: 24px;
}
.section-2 li.active-marker {
left: 49px;
}
.section-3 li.active-marker {
left: 74px;
}
.section-4 li.active-marker {
left: 99px;
}
/* etc */
{
"version": "0.4.9",
"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.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