|
@ -9,14 +9,15 @@ |
|
|
|
|
|
|
|
|
export default |
|
|
export default |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
state: |
|
|
state: |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
options: { |
|
|
|
|
|
offset: 100 |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -31,62 +32,90 @@ |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* setting innerHTML |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
onMounted() |
|
|
onMounted() |
|
|
{ |
|
|
{ |
|
|
|
|
|
// adding content to wrapper |
|
|
const wrapper = this.$('.tiny-one-page__inner'); |
|
|
const wrapper = this.$('.tiny-one-page__inner'); |
|
|
wrapper.innerHTML = this.content; |
|
|
wrapper.innerHTML = this.content; |
|
|
|
|
|
|
|
|
// adding scroll smooth |
|
|
|
|
|
|
|
|
// adding scroll smooth, get all elements with hash |
|
|
this.scroll = new SmoothScroll('.tiny-one-page__inner a[href*="#"]', { |
|
|
this.scroll = new SmoothScroll('.tiny-one-page__inner a[href*="#"]', { |
|
|
offset: function() { |
|
|
offset: function() { |
|
|
return 100; |
|
|
|
|
|
|
|
|
return this.state.options.offset; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
window.addEventListener('scroll', this.handleScroll.bind(this), false); |
|
|
window.addEventListener('scroll', this.handleScroll.bind(this), false); |
|
|
|
|
|
|
|
|
if (window.location.hash) { |
|
|
if (window.location.hash) { |
|
|
this.$(".tiny-one-page__inner a[href$='" + window.location.hash + "']") |
|
|
|
|
|
.parentElement |
|
|
|
|
|
.classList |
|
|
|
|
|
.add('current'); |
|
|
|
|
|
|
|
|
this.addClass(this.$(".tiny-one-page__inner a[href$='" + window.location.hash + "']")); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.addClass(this.$$(".tiny-one-page__inner a")[0]); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param {Object} element |
|
|
|
|
|
* @return {Boolean} |
|
|
|
|
|
*/ |
|
|
isVisible(element) |
|
|
isVisible(element) |
|
|
{ |
|
|
{ |
|
|
return ( |
|
|
|
|
|
((element.offsetHeight + element.offsetTop) - this.options.offset) > window.pageYOffset |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
return ((element.offsetHeight + element.offsetTop) - this.state.options.offset) > window.pageYOffset; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* add css class to parent element |
|
|
* |
|
|
* |
|
|
* @param {[type]} event [description] |
|
|
|
|
|
* @return {[type]} [description] |
|
|
|
|
|
|
|
|
* @param {Object} element |
|
|
*/ |
|
|
*/ |
|
|
handleScroll(event) { |
|
|
|
|
|
|
|
|
addClass(element) |
|
|
|
|
|
{ |
|
|
|
|
|
element |
|
|
|
|
|
.parentElement |
|
|
|
|
|
.classList |
|
|
|
|
|
.add('current'); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* remove css class from parent element |
|
|
|
|
|
* |
|
|
|
|
|
* @param {Object} element |
|
|
|
|
|
*/ |
|
|
|
|
|
removeClass(element) |
|
|
|
|
|
{ |
|
|
|
|
|
element |
|
|
|
|
|
.parentElement |
|
|
|
|
|
.classList |
|
|
|
|
|
.remove('current'); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* handle scrolling, |
|
|
|
|
|
* |
|
|
|
|
|
* @param {Object} event |
|
|
|
|
|
*/ |
|
|
|
|
|
handleScroll(event) |
|
|
|
|
|
{ |
|
|
// get elements |
|
|
// get elements |
|
|
const elements = this.$$('.tiny-one-page__inner a'); |
|
|
const elements = this.$$('.tiny-one-page__inner a'); |
|
|
|
|
|
|
|
|
// if found |
|
|
// if found |
|
|
let hasFound = false; |
|
|
let hasFound = false; |
|
|
|
|
|
|
|
|
elements.forEach(function(index, target) { |
|
|
|
|
|
|
|
|
elements.forEach(function(element, index) { |
|
|
|
|
|
|
|
|
// get element by hash |
|
|
|
|
|
const hash = target.hash; |
|
|
|
|
|
|
|
|
const target = document.querySelector(element.hash); |
|
|
|
|
|
|
|
|
if (this.isVisible(element, hash) && hasFound === false) { |
|
|
|
|
|
target.add('current'); |
|
|
|
|
|
|
|
|
if (this.isVisible(target) && hasFound === false) { |
|
|
|
|
|
this.addClass(element); |
|
|
hasFound = true; |
|
|
hasFound = true; |
|
|
} else { |
|
|
} else { |
|
|
target.classList.remove('current'); |
|
|
|
|
|
|
|
|
this.removeClass(element); |
|
|
} |
|
|
} |
|
|
}.bind(this)); |
|
|
}.bind(this)); |
|
|
} |
|
|
} |
|
|