Guest User

Untitled

a guest
Aug 19th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //main class
  2. function Section(){
  3.     this.currentKey;
  4.     this.offsets = [];
  5.     this.sectionID = ['#a','#b','#c','#d'];
  6. }
  7.  
  8. //constructor
  9. Section.prototype.construct = function(topOffset) {
  10.  
  11.     //sets the offsets values
  12.     for(var u = 0; u < this.sectionID.length; u++) {
  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.         if (topOffset >= this.offsets[i] && topOffset < this.offsets[i + 1]) {
  19.             this.currentKey = i;
  20.         }
  21.     }
  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();
Advertisement
Add Comment
Please, Sign In to add comment