Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onscroll function is not working for Chrome

Tags:

javascript

The below code is working fine for Firefox browser. But, not chrome. What is the issue in below code ?

window.onload = function()
{
   document.body.onscroll =  Test.callFn;
}

var Test = new function()
{
   this.callFn = function()
   {
      console.log("Calling this function");
   }
}

Thanks

like image 615
sprabhakaran Avatar asked Jun 10 '13 04:06

sprabhakaran


People also ask

How do you use OnScroll in CSS?

This onscroll attribute works when an element scrollbar is being scrolled. To create a scrollbar in an element, use the CSS overflow property. Supported Tags: It supports all HTML elements. Attribute: This attribute is supported by all HTML elements and the attribute works when script triggered. science.

What is the HTML DOM OnScroll event?

The HTML DOM onscroll event occurs when a scrollbar is used. CSS overflow is used to create a scrollbar. HTML stands for Hyper Text Markup Language. It is used to design web pages using markup language. HTML is the combination of Hypertext and Markup language.

What is the syntax for scroll event in JavaScript?

Syntax: 1 In HTML: <element onscroll="myScript"> 2 In JavaScript: object.onscroll = function () {myScript}; 3 In JavaScript, using the addEventListener () method: object.addEventListener ("scroll", myScript);

How do I toggle between class names on different scroll positions?

Toggle between class names on different scroll positions - When the user scrolls down 50 pixels from the top of the page, the class name "test" will be added to an element (and removed when scrolled up again). Slide in an element when the user has scrolled down 350 pixels from the top of the page (add the slideUp class):


Video Answer


1 Answers

This might also happen when the height of html and body tags is set to 100% and the scroll event does not fire for window nor document. To check which element is scrolled I slightly modified Aaron Mason's snippet which wasn't working for me either:

document.querySelectorAll('*').forEach(function(elem) {
    elem.addEventListener('scroll', function() {
        console.log(this);
    });
}); 
like image 148
t3rmian Avatar answered Nov 16 '22 03:11

t3rmian