Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2362 Lượt xem

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???

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
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');
}
},
})


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 5 25
2451
2
thg 5 25
5786
1
thg 3 25
1626
4
thg 3 25
4420
3
thg 2 25
5400