Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
2372 Zobrazení

hi everyone

my odoo version is 17

for example:

window.addEventListener('scroll',()=>{

let scrollTop = document.documentElement.scrollTop;

​if(scrollTop > 100){

​​console.log('more than 100px')

​}else{

​​console.log('lower than 100px')

​}

})

but not working for me

do you have solution???

Avatar
Zrušit
Autor Nejlepší odpověď
this code work for me :)


/** @odoo-module */
import publicWidget from '@web/legacy/js/public/public_widget';

publicWidget.registry.customMenuBar = publicWidget.Widget.extend({
selector: '#wrapwrap',

start: function () {
this.$el.on('scroll', this._onScroll.bind(this));
return this._super();
},

_onScroll: function () {
var scrollTop = this.$el.scrollTop();
if (scrollTop > 100) {
console.log('More than 100px');
} else {
console.log('Lower than 100px');
}
},
})


Avatar
Zrušit
Nejlepší odpověď

Hi Amin,

can you try window property Try like 

window.scrollY may be work


window.addEventListener('scroll', () => { if (window.scrollY > 100) { console.log('more than 100px'); } else { console.log('lower than 100px'); } });
Thanks.


Avatar
Zrušit
Autor

Thank you for your answer.. but unfortunately it doesn't work
Only at the moment of the initial loading , the if condition occurs
And it doesn't happen with scroll

Related Posts Odpovědi Zobrazení Aktivita
4
kvě 25
2462
2
kvě 25
5802
1
bře 25
1637
4
bře 25
4426
3
úno 25
5413