Created
July 2, 2014 01:56
-
-
Save syads321/8a01a10e33e7b52b7274 to your computer and use it in GitHub Desktop.
Animframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var raf = window.mozRequestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
window.oRequestAnimationFrame; | |
Bridge.animLoop = function( render, element ) { | |
var running, lastFrame = +new Date; | |
function loop( now ) { | |
if ( running !== false ) { | |
raf ? | |
raf( loop, element ) : | |
// fallback to setTimeout | |
setTimeout( loop, 16 ); | |
// Make sure to use a valid time, since: | |
// - Chrome 10 doesn't return it at all | |
// - setTimeout returns the actual timeout | |
now = now && now > 1E4 ? now : +new Date; | |
var deltaT = now - lastFrame; | |
// do not render frame when deltaT is too high | |
if ( deltaT < 160 ) { | |
running = render( deltaT, now ); | |
} | |
lastFrame = now; | |
} | |
} | |
loop(); | |
}; | |
$(document).ready(function () { | |
var t = null; | |
var itemwidth = $('span.news').outerWidth(); | |
var multiplier = 0.2; | |
var interval = 60 * multiplier; | |
var cacheinterval = interval; | |
Bridge.animLoop(function() { | |
interval-- | |
if (interval < 0) { | |
console.log('runns') | |
interval = cacheinterval; | |
if ($('span.news').position().left < (0 - itemwidth)) { | |
$('span.news').css('left', $('span.news').parent().width() + 'px'); | |
} else { | |
$('span.news').css('left', $('span.news').position().left - 10 + 'px'); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment