I need to make a function like this "device.browser.scroll().top" how do I make a function do that and get the value from and object, my code says undefined all the time.
let device = {};
device.browser = {};
device.browser.scroll = (el = window) => {
return {
top: el.pageXOffset || el.scrollLeft,
Left: el.pageYOffset || el.scrollTop,
}
}
console.log('scrollTop', device.browser.scroll().top);
html, body {
height: 100%;
}
.wrapper div {
height: 100vh;
}
.wrapper div:nth-child(1) {
background: red;
}
.wrapper div:nth-child(2) {
background: green;
}
.wrapper div:nth-child(3) {
background: blue
}
<div class="wrapper">
<div></div>
<div></div>
<div></div>
</div>