SHOW:
|
|
- or go back to the newest paste.
| 1 | - | //main class |
| 1 | + | //javascript.js************** |
| 2 | - | function Section(){
|
| 2 | + | function Section() {
|
| 3 | - | this.currentKey; |
| 3 | + | this.currentKey; |
| 4 | - | this.offsets = []; |
| 4 | + | this.offsets = []; |
| 5 | - | this.sectionID = ['#a','#b','#c','#d']; |
| 5 | + | this.sectionID; |
| 6 | this.prefixPath; | |
| 7 | this.topOffset; | |
| 8 | } | |
| 9 | - | Section.prototype.construct = function(topOffset) {
|
| 9 | + | |
| 10 | //constructor | |
| 11 | - | //sets the offsets values |
| 11 | + | Section.prototype.construct = function (topOffset) {
|
| 12 | - | for(var u = 0; u < this.sectionID.length; u++) {
|
| 12 | + | |
| 13 | - | this.offsets[u] = $(this.sectionID[u]).offset().top; |
| 13 | + | this.sectionID = ['heim', 'tilbud', 'galleri', 'feedback']; |
| 14 | - | } |
| 14 | + | this.prefixPath = 'body>section#content>section#'; |
| 15 | - | |
| 15 | + | this.topOffset = topOffset; |
| 16 | - | //gets the currentKey |
| 16 | + | |
| 17 | - | for (var i = 0; i < offsets.length; i++) {
|
| 17 | + | //sets the offsets values |
| 18 | - | if (topOffset >= this.offsets[i] && topOffset < this.offsets[i + 1]) {
|
| 18 | + | for (var u = 0; u < this.sectionID.length; u++) {
|
| 19 | - | this.currentKey = i; |
| 19 | + | this.offsets[u] = $(this.prefixPath+this.sectionID[u]).offset().top; |
| 20 | - | } |
| 20 | + | } |
| 21 | - | } |
| 21 | + | return false; |
| 22 | } | |
| 23 | ||
| 24 | //change attribute | |
| 25 | - | Section.prototype.getCurrent = function() {
|
| 25 | + | Section.prototype.changeIDString = function () {
|
| 26 | - | return this.sectionID[this.currentKey]; |
| 26 | + | //gets the currentKey |
| 27 | for (var i = 0; i < this.offsets.length; i++) {
| |
| 28 | if (i + 1 != this.offsets.length) {
| |
| 29 | if (this.topOffset >= this.offsets[i] && this.topOffset < this.offsets[i + 1]) {
| |
| 30 | - | Section.prototype.setAttributes = function(){
|
| 30 | + | this.currentKey = i; |
| 31 | - | $('#current').Attr('id').remove();
|
| 31 | + | break; |
| 32 | - | $(this.getCurrent).Attr('id','#current');
|
| 32 | + | } |
| 33 | } else if (this.topOffset >= this.offsets[i]) {
| |
| 34 | this.currentKey = i; | |
| 35 | break; | |
| 36 | - | Section.construct(topOffset,offsets); |
| 36 | + | } |
| 37 | - | Section.setAttributes(); |
| 37 | + | } |
| 38 | return false; | |
| 39 | } | |
| 40 | ||
| 41 | //get current | |
| 42 | Section.prototype.getIDString = function () {
| |
| 43 | return this.sectionID[this.currentKey]; | |
| 44 | } | |
| 45 | ||
| 46 | //set classes | |
| 47 | Section.prototype.setAttributes = function () {
| |
| 48 | $('#current').removeAttr('id');
| |
| 49 | $('[data-gotoSection="#' + this.getIDString() + '"]').attr('id', 'current');
| |
| 50 | } | |
| 51 | ||
| 52 | ||
| 53 | var Section = new Section(); | |
| 54 | ||
| 55 | ||
| 56 | ||
| 57 | //footer.php***************** | |
| 58 | [...] | |
| 59 | //find the section | |
| 60 | Section.construct(topOffset); | |
| 61 | Section.changeIDString(); | |
| 62 | Section.setAttributes(); | |
| 63 | [...] |