Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //javascript.js**************
- function Section() {
- this.currentKey;
- this.offsets;
- this.sectionID;
- this.prefixPath;
- this.topOffset;
- }
- //constructor
- Section.prototype.construct = function (topOffset) {
- this.sectionID = ['heim', 'tilbud', 'galleri', 'feedback'];
- this.offsets = [];
- this.prefixPath = 'body>section#content>section#';
- this.topOffset = topOffset;
- //sets the offsets values
- for (var u = 0; u < this.sectionID.length; u++) {
- this.offsets[u] = $(this.prefixPath+this.sectionID[u]).offset().top;
- }
- return false;
- }
- //change attribute
- Section.prototype.changeIDString = function () {
- //gets the currentKey
- for (var i = 0; i < this.offsets.length; i++) {
- if (i + 1 != this.offsets.length) {
- if (this.topOffset >= this.offsets[i] && this.topOffset < this.offsets[i + 1]) {
- this.currentKey = i;
- break;
- }
- } else if (this.topOffset >= this.offsets[i]) {
- this.currentKey = i;
- break;
- }
- }
- return false;
- }
- //get current
- Section.prototype.getIDString = function () {
- return this.sectionID[this.currentKey];
- }
- //set classes
- Section.prototype.setAttributes = function () {
- $('#current').removeAttr('id');
- $('[data-gotoSection="#' + this.getIDString() + '"]').attr('id', 'current');
- }
- var Section = new Section();
- //footer.php*****************
- [...]
- //find the section
- Section.construct(topOffset);
- Section.changeIDString();
- Section.setAttributes();
- [...]
Advertisement
Add Comment
Please, Sign In to add comment