Problem with requestAnimationFrame in Safari
Agoreddah opened this issue · 1 comments
Some specific versions of Safari (and also some other older browsers) supports requestAnimationFrame only with prefix. In this case, line 216 should be modified to handle these scenarios, f.e.:
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (function() {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback, element) {
window.setTimeout(callback, 1000 / 60);
};
})();
}
function animate(){
window.requestAnimationFrame(function (time) {
if (startTime === 0) {
startTime = time;
}
anim(insertElem, insertFrom, insertTo, removeElem, removeFrom, removeTo, transitionDuration, startTime, time, easeFunc);
});
}
animate();
hi @Agoreddah thank you very much for your report 😊
simple-slider used to have a requestAnimationFrame
polyfill internally in the past but it was eventually removed when I started the effort of modernizing the codebase, and there are some logical arguments behind that decision:
- At some point I decided to really switch the focus of the lib towards the small file size and including a polyfill would def bloat the final result
- The requestAnimationFrame API is quite well supported across browsers these days
- Separation of concerns, there are many
requestAnimationFrame
polyfills available out there
If anyone happen to stumble upon this issue to help with the same problem in the future I would recommend checking out raf which is one of the earliest requestAnimationFrame
polyfills available and quite easy to use.
Thanks again for bringing the point up and all the best 👍