-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Effects: use requestAnimationFrame timestamp if available #3151
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,24 +27,31 @@ var | |
rfxtypes = /^(?:toggle|show|hide)$/, | ||
rrun = /queueHooks$/; | ||
|
||
function schedule() { | ||
function schedule( timestamp ) { | ||
if ( inProgress ) { | ||
if ( document.hidden === false && window.requestAnimationFrame ) { | ||
if ( document.hidden === false ) { | ||
window.requestAnimationFrame( schedule ); | ||
} else { | ||
window.setTimeout( schedule, jQuery.fx.interval ); | ||
} | ||
|
||
jQuery.fx.tick(); | ||
jQuery.fx.tick( timestamp ); | ||
} | ||
} | ||
|
||
// We need to be using Date.now() or performance.now() consistently as they return different | ||
// values: performance.now() counter starts on page load. | ||
// Support: IE <10, Safari <8.0, iOS <9, Android <4.4, Node with jsdom 9.4 | ||
function getTimestamp() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the comments, shouldn't we have something more like this? getTimestamp = window.performance && typeof window.performance.now === "function" ?
// or window.performance.now.bind( window.performance )
jQuery.proxy( window.performance, "now" ) :
jQuery.now; If the complaint is about testing, then we just need an iframe test in which the sandbox is mocked before loading jQuery. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it should work, I'll try it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, test setup is run after jQuery is sourced so this would freeze There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could put the The fact that we can't reliably mock stuff before jQuery is loaded is obviously a problem but this is an issue bigger than this PR. |
||
return window.performance.now(); | ||
} | ||
|
||
// Animations created synchronously will run synchronously | ||
function createFxNow() { | ||
window.setTimeout( function() { | ||
fxNow = undefined; | ||
} ); | ||
return ( fxNow = Date.now() ); | ||
return ( fxNow = getTimestamp() ); | ||
} | ||
|
||
// Generate parameters to create a standard animation | ||
|
@@ -644,12 +651,12 @@ jQuery.each( { | |
} ); | ||
|
||
jQuery.timers = []; | ||
jQuery.fx.tick = function() { | ||
jQuery.fx.tick = function( timestamp ) { | ||
var timer, | ||
i = 0, | ||
timers = jQuery.timers; | ||
|
||
fxNow = Date.now(); | ||
fxNow = timestamp || getTimestamp(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if still needs this, since this change was added for the old ipad zooming thing - https://bugs.jquery.com/ticket/12837, maybe it's not required anymore. Or should we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just removing this line (& the one setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could optionally change |
||
|
||
for ( ; i < timers.length; i++ ) { | ||
timer = timers[ i ]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>Effects: matching timestamps</title> | ||
</head> | ||
<body> | ||
<script src="../../jquery.js"></script> | ||
<script src="../iframeTest.js"></script> | ||
<div id="test-div" style="height: 1000px;"></div> | ||
<script> | ||
//<![CDATA[ | ||
setTimeout( function () { | ||
|
||
// Handle a timeout. | ||
startIframeTest( false, "The test timed out" ); | ||
}, 5000 ); | ||
|
||
var maxNow = 0; | ||
|
||
jQuery( "#test-div" ).animate( { | ||
height: '2000px', | ||
}, { | ||
duration: 300, | ||
step: function( now ) { | ||
if ( maxNow - now > 100 ) { | ||
startIframeTest( false, "Animation is stepping back from " + maxNow + " to " + now ); | ||
} | ||
maxNow = Math.max( now, maxNow ); | ||
}, | ||
complete: function() { | ||
startIframeTest( true ); | ||
} | ||
} ); | ||
//]]> | ||
</script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use
jQuery.now()
for all the browsers that don't have the rAF timestamp? Which browsers are affected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is also used in
createFxNow()
which, I think, is not limited to old browsers?