简体   繁体   中英

My window.scrolltop not working

I am using window.scroll function, but window.scrollTop didn't return any value in lightning controller. Help me.

initialize : function(component, event, helper) {
            var isHidden = false
            var lastScrollTop = 0
            console.log('heyyyyyy');
            window.addEventListener('scroll', function() {
                console.log('heyasasyyyyy');
                var scrollTop =  document.documentElement.scrollTop;
                var offset = scrollTop-lastScrollTop ;
                lastScrollTop = scrollTop ;
                console.log(scrollTop+'++++'+offset+'++++++'+lastScrollTop);
            });

        },

You have a typo: 3rd row - latScrollTop instead of la s tScrollTop.

Fixed Code:

initialize : function(component, event, helper) {
            var isHidden = false
            var lastScrollTop = 0
            console.log('heyyyyyy');
            window.addEventListener('scroll', function() {
                console.log('heyasasyyyyy');
                var scrollTop =  document.documentElement.scrollTop;
                var offset = scrollTop-lastScrollTop ;
                lastScrollTop = scrollTop ;
                console.log(scrollTop+'++++'+offset+'++++++'+lastScrollTop);
            });

        },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM