Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main class
- function Section(){
- this.currentKey;
- this.offsets = [];
- this.sectionID = ['#a','#b','#c','#d'];
- }
- //constructor
- Section.prototype.construct = function(topOffset) {
- //sets the offsets values
- for(var u = 0; u < this.sectionID.length; u++) {
- this.offsets[u] = $(this.sectionID[u]).offset().top;
- }
- //gets the currentKey
- for (var i = 0; i < offsets.length; i++) {
- if (topOffset >= this.offsets[i] && topOffset < this.offsets[i + 1]) {
- this.currentKey = i;
- }
- }
- }
- //get current
- Section.prototype.getCurrent = function() {
- return this.sectionID[this.currentKey];
- }
- //set classes
- Section.prototype.setAttributes = function(){
- $('#current').Attr('id').remove();
- $(this.getCurrent).Attr('id','#current');
- }
- var Section = new Section();
- Section.construct(topOffset,offsets);
- Section.setAttributes();
Advertisement
Add Comment
Please, Sign In to add comment