mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix absolute / fixed navbar position
This commit is contained in:
parent
c7b6788288
commit
1217578202
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<teleport to="#content_conainter .container.content .container">
|
<teleport to="#content_conainter .container.content .container">
|
||||||
<div class="sticky-section" id="navmap">
|
<div id="navmap">
|
||||||
<nav>
|
<nav>
|
||||||
<a href="#top">
|
<a href="#top">
|
||||||
<i class="fa fa-fw fa-square-o"></i>
|
<i class="fa fa-fw fa-square-o"></i>
|
||||||
@ -44,32 +44,104 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const stickyNav = document.querySelector('#navmap');
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "StickyNav",
|
name: "StickyNav",
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
header: document.querySelector("header.navigation.container"),
|
||||||
|
bannerName: document.querySelector("#header-accompanying_course-name"),
|
||||||
|
bannerDetails: document.querySelector("#header-accompanying_course-details"),
|
||||||
|
stickyNav: null,
|
||||||
|
sumBanner: null
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
accompanyingCourse() {
|
accompanyingCourse() {
|
||||||
return this.$store.state.accompanyingCourse
|
return this.$store.state.accompanyingCourse
|
||||||
},
|
},
|
||||||
|
top() {
|
||||||
|
//return window.getComputedStyle(this.stickyNav).getPropertyValue('top'); //
|
||||||
|
return 30; //px
|
||||||
|
},
|
||||||
|
//sumBanner() {
|
||||||
|
// return this.header.offsetHeight + this.bannerName.offsetHeight + this.bannerDetails.offsetHeight;
|
||||||
|
//}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.bing();
|
this.ready();
|
||||||
|
window.addEventListener('scroll', this.handleScroll); // scroll de la souris
|
||||||
|
},
|
||||||
|
destroyed() {
|
||||||
|
window.removeEventListener('scroll', this.handleScroll); // scroll de la souris
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
bing() {
|
ready() {
|
||||||
console.log('coucou');
|
|
||||||
|
|
||||||
|
this.stickyNav = document.querySelector('#navmap');
|
||||||
|
this.sumBanner = this.header.offsetHeight + this.bannerName.offsetHeight + this.bannerDetails.offsetHeight;
|
||||||
|
|
||||||
|
const resizeObserver = new ResizeObserver(entries => { // FF/Chrome!
|
||||||
|
|
||||||
|
console.log('header', this.header.offsetHeight);
|
||||||
|
//this.header = this.header.offsetHeight;
|
||||||
|
console.log('bannerName', this.bannerName.offsetHeight);
|
||||||
|
//this.bannerName = this.bannerName.offsetHeight;
|
||||||
|
console.log('bannerDetails', this.bannerDetails.offsetHeight);
|
||||||
|
//this.bannerDetails = this.bannerDetails.offsetHeight;
|
||||||
|
|
||||||
|
this.sumBanner = this.header.offsetHeight + this.bannerName.offsetHeight + this.bannerDetails.offsetHeight;
|
||||||
|
console.log('sum', this.sumBanner);
|
||||||
|
console.log('--');
|
||||||
|
|
||||||
|
});
|
||||||
|
resizeObserver.observe(this.header);
|
||||||
|
resizeObserver.observe(this.bannerName);
|
||||||
|
resizeObserver.observe(this.bannerDetails);
|
||||||
|
|
||||||
|
},
|
||||||
|
handleScroll(event) {
|
||||||
|
|
||||||
|
//console.log('top !!', this.top);
|
||||||
|
//console.log(this.stickyNav);
|
||||||
|
let pos = this.findPosition(this.stickyNav);
|
||||||
|
//console.log(window.scrollY);
|
||||||
|
console.log('sum2', this.sumBanner);
|
||||||
|
let top = this.sumBanner + this.top - window.scrollY; //pos['y']
|
||||||
|
if (top > 25) {
|
||||||
|
console.log('absolute', pos['y']);
|
||||||
|
this.stickyNav.style.position = 'absolute';
|
||||||
|
this.stickyNav.style.left = '-60px';
|
||||||
|
} else {
|
||||||
|
console.log('fixed', pos['y']);
|
||||||
|
this.stickyNav.style.position = 'fixed';
|
||||||
|
this.stickyNav.style.left = pos['x'] + 'px';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
findPosition(element) {
|
||||||
|
let posX = 0, posY = 0;
|
||||||
|
do {
|
||||||
|
posX += element.offsetLeft;
|
||||||
|
posY += element.offsetTop;
|
||||||
|
element = element.offsetParent;
|
||||||
|
}
|
||||||
|
while( element != null );
|
||||||
|
|
||||||
|
let pos = [];
|
||||||
|
pos['x'] = posX;
|
||||||
|
pos['y'] = posY;
|
||||||
|
|
||||||
|
return pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
div.sticky-section {
|
div#navmap {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 33px;
|
top: 30px;
|
||||||
left: -10%;
|
left: -60px; //-10%;
|
||||||
nav {
|
nav {
|
||||||
font-size: small;
|
font-size: small;
|
||||||
a {
|
a {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user