SHOW:
|
|
- or go back to the newest paste.
| 1 | //main class | |
| 2 | function Section(){
| |
| 3 | - | this.current; |
| 3 | + | this.currentKey; |
| 4 | this.offsets = []; | |
| 5 | this.sectionID = ['#a','#b','#c','#d']; | |
| 6 | } | |
| 7 | - | Section.prototype.construct = function(topOffset,offsets) {
|
| 7 | + | |
| 8 | - | |
| 8 | + | |
| 9 | - | for (var i = 0; i < offsets.length; i++) {
|
| 9 | + | Section.prototype.construct = function(topOffset) {
|
| 10 | - | if (topOffset >= offsets[i] && topOffset < offsets[i + 1]) {
|
| 10 | + | |
| 11 | - | this.current = offset[i]; |
| 11 | + | //sets the offsets values |
| 12 | - | } |
| 12 | + | for(var u = 0; u < this.sectionID.length; u++) {
|
| 13 | - | } |
| 13 | + | this.offsets[u] = $(this.sectionID[u]).offset().top; |
| 14 | } | |
| 15 | ||
| 16 | //gets the currentKey | |
| 17 | for (var i = 0; i < offsets.length; i++) {
| |
| 18 | - | return this.current; |
| 18 | + | if (topOffset >= this.offsets[i] && topOffset < this.offsets[i + 1]) {
|
| 19 | this.currentKey = i; | |
| 20 | } | |
| 21 | } | |
| 22 | - | Section.construct(topOffset,offsets); |
| 22 | + | |
| 23 | ||
| 24 | //get current | |
| 25 | Section.prototype.getCurrent = function() {
| |
| 26 | return this.sectionID[this.currentKey]; | |
| 27 | } | |
| 28 | ||
| 29 | //set classes | |
| 30 | Section.prototype.setAttributes = function(){
| |
| 31 | $('#current').Attr('id').remove();
| |
| 32 | $(this.getCurrent).Attr('id','#current');
| |
| 33 | } | |
| 34 | ||
| 35 | var Section = new Section(); | |
| 36 | Section.construct(topOffset,offsets); | |
| 37 | Section.setAttributes(); |