zishu's blog

zishu's blog

一个热爱生活的博主。https://zishu.me

In IE10, the comma symbol cannot be left blank.

$("#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. I had no choice but to run it in the IE browser, and I found that this line of code would throw an error. What's going on?

Let's analyze it briefly. It's similar to the syntax of a timer 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 point. Why does it throw an error?

At this point, I noticed the , after 500. I suddenly thought of a possibility and decided to remove the ,. As expected, the console no longer showed an error.

I speculate that this is caused by the mechanism of IE. When the browser recognizes the ,, it automatically assumes that there is a statement following it. However, if it is left blank, it produces a different result than what the browser expects, leading to an error. Perhaps the IE engine has stricter requirements.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.