-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
wrong value for ifvisible.now() the first time it's called #21
Comments
I solved it by calling |
I see. If you are only using |
I can't call |
Sorry for the late reply |
I was only using |
This must be some other problem, as you can see here https://github.com/serkanyersen/ifvisible.js/blob/master/src/ifvisible.coffee#L433 |
Weird. Maybe the change wasn't on |
Checked the history, Line 155 in 35a5b95
Must be some other bug. I'll look out for it |
I ran into this as well while trying to rely on ifvisible.Now( 'hidden' ) to prove visibility without the idle tracking. It's because init() (which is called by now() ) calls trackIdleStatus() at return, which in turn calls wakeUp(), resetting the status to 'active'. I solved this by returning this from init(): return trackIdleStatus(), initVisibility(); where the definition of initVisibility() is as follows: initVisibility = function() {
if (doc[hidden]) {
return ifvisible.blur();
} else {
return ifvisible.focus();
}
}; Note: this fix does not work with IE9 or earlier (I don't need the legacy support). I'm not sure there is any way to make it work with IE9, as initial state depends on the html5 visibility API. Hope this helps. My full compiled init, fyi: init = function() {
var blur;
if (initialized) {
return true;
}
if (hidden === false) {
blur = "blur";
if (ie < 9) {
blur = "focusout";
}
addEvent(window, blur, function() {
return ifvisible.blur();
});
addEvent(window, "focus", function() {
return ifvisible.focus();
});
} else {
addEvent(doc, visibilityChange, initVisibility, false);
}
initialized = true;
//The initVisibility call will not work in IE 9 or less, but it doesn't error out.
//It's called here as trackIdleStatus() calls wakeUp(), resetting the visibility status to true
return trackIdleStatus(), initVisibility();
}; |
@csilcock Thanks for detail explanation, I'll look into this tonight. |
Hi, I can confirm ifvisible.now() always returns 'true' when used plainly without listeners. I would like to check if a page was opened 'in a new tab' = 'hidden in background'. |
I wanted to use this plugin for the sole purpose of delaying an animation until a user actually sees the page for the first time. But as mentioned before, the ifvisible.now() returns true if the page is opened in a new tab (and not yet visible) as well. |
This problem is now fixed on the beta version. Please check my comment on #38 |
ping, it still does not work in |
|
+1 still not working |
Reproduced in Chrome Version 41.0.2272.76 (64-bit), Yosemite 10.10.2 (14C109).
The text was updated successfully, but these errors were encountered: