question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll event does't appear to trigger with window.scrollTo

See original GitHub issue

I need to detect changes to the DOM after a scroll event, however browser.document.window.scrollTo() doesn’t appear to do anything.

This is what I have:

var assert = require('assert'),
    Browser = require('zombie');

Browser.localhost('http://localhost:8080', 8080);

var browser = Browser.create();
it('Should load content on scroll', function(done){

    browser.visit('/', function(error){
        assert.ifError(error);
        browser.assert.success();

        // this event never triggers
        browser.document.window.addEventListener('scroll', function(){
            console.log('scrolling...');
        });

        browser.document.window.scrollTo(100, 100);

        console.log(browser.document.documentElement.scrollTop);  // outputs '0'
        console.log(browser.document.documentElement.scrollLeft); // outputs '0'

        done();
    });
});

p.s This thing is amazing 👍

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PickleJrcommented, Jun 4, 2018

*Disclaimer: I haven’t used zombie that much, I’ve only stumbled here from a Google Search.

I was having the same issue in Firefox Development Edition and Microsoft Edge. I’m not sure if Chrome has this issue or not. I was able to remedy the issue by calling window.dispatchEvent(new Event('scroll')); after the window.scrollTo(…) statement.

I’m not sure if this will help everybody, but it might help somebody.

0reactions
assafcommented, Nov 24, 2015

I don’t think this is implemented anywhere. This is classical open source, contributors solve whatever problem they have, and contribute it upstream if they want to. No one is working from a roadmap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to trigger an on scroll event without scrolling
If you want to fire a scroll event, just literally scroll to where you already are by typing window.scrollTo(window.scrollX, window.
Read more >
Document: scroll event - Web APIs - MDN Web Docs - Mozilla
The scroll event fires when the document view has been scrolled. To detect when scrolling has completed, see the Document: scrollend event.
Read more >
JavaScript Scroll Events, Event Throttling & Passive Events
In this tutorial, you will learn about the JavaScript scroll events and how to handle scroll event properly.
Read more >
Window scrollTo() Method - W3Schools
Window scrollTo () ; Syntax. window.scrollTo(x, y) ; Parameters · Required. The coordinate to scroll to (horizontally), in pixels. y, Required. The coordinate...
Read more >
How to detect a window scroll event in a Reactive application
$(window).scroll(function() { if($(window).scrollTop() + $(window).height() > $(document).height() - 100) { ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found