Javascript setTimeout issue
I have a bar that shows up (in rails) from a flash hash. I want it to explode with jquery, so I added this code:
<script>
setTimeout("derp()", 2000);
function derp() {
$("span").hide("explode", { pieces: 16 }, 500);
}
</script>
Works fine except in a couple of seconds it appears again and then something extremely strange happens - th开发者_如何学Ce path to googleapis is shown and the page becomes barely responsive. What gives?
This is the proper way of using setTimeout
<script type='text/javascript'>
setTimeout(function () {
$("span").hide("explode",{ pieces: 16 }, 500);
}, 2000);
</script>
running it the way you had is like using eval(), you should avoid passing a string in setTimeout()
you could also pass your function like this:
setTimeout(derp,500);
精彩评论