Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggers 'inview' event with isInView true when element is not really visible #6

Open
givankin opened this issue Aug 12, 2011 · 2 comments

Comments

@givankin
Copy link

My case was creating elements in an inactive tab (jquery ui tab, not browser's one, so just hidden div). Adding 'inview' event listeners to such elements immediately triggered 'inview' despite they were not really visible.

Adding

if (!$element.is(':visible')) {
    continue;
}

to checkInView after variables declaration worked for me, but maybe there's a better way.

Really sorry for robust issuing, but have no time now for pull request or more elaborate investigation.

@mattandrews
Copy link

Yes, have seen this behaviour too. Not even using a "hidden" div, just by changing my browser focus to another tab then dynamically injecting an element into the other tab via AJAX triggers the inView callback despite the tab not actually being in view.

@joshribakoff
Copy link

I'm having another similar issue. Here is my markup

<div style="display:none"></div>

I would expect the event to fire only when I scroll to where that element "would be" on the page if it were visible. Instead it fires immediately on page load even if that div is all the way in the footer, well below the fold. Change it to this works fine:

<div style="display:block"></div>

My workaround had to be a bit different than @aabakym. What I ended up doing was instead of binding the inview event directly to my hidden div, I used jquery to insert an empty but technically visible "marker" div and bind to that instead:

$('.hidden').after('<div class="visible-marker"></div>');
$('.visible-marker').livequery('inview', function() {
  // now use jquery to find the div adjacent to $(this) to traverse back to the .hidden div.
});

It would technically be possible for jquery.inview to handle this for me internally so its abstracted away from me as a user.

GerHobbelt pushed a commit to GerHobbelt/jquery.inview that referenced this issue Oct 12, 2015
Namespace events, expose checkInView function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants