$("#test").click(function () {
$('html,body').animate({ 'scrollTop': '0' }, 500,)
})
This line of code uses the jQuery syntax, with a 500 millisecond animation. It works fine in browsers like Chrome and runs normally.
However, today while working on a project, I was required to make the code compatible with IE10. So, I had to run it in the IE browser and found that this line of code throws an error. What could be the reason?
Let's analyze it briefly. It's somewhat similar to the syntax of timers in JavaScript, like setTimeout, with two parameters representing the specified time and the interval time.
The animate property is for animations, and it takes 500 milliseconds to complete. But that's not the main issue. Why does it throw an error?
At this point, I noticed the comma (,) after 500, and suddenly I thought of a possibility: let's remove the comma. As expected, the console no longer shows an error.
I speculate that this is caused by the mechanism of IE. When the browser recognizes the comma, it automatically assumes that there is a statement following it. But if it is left empty, it doesn't match the browser's expectation and results in an error. Perhaps the IE engine has stricter requirements.