关于jQuery中的事件和动画
在学习jQuery中,碰到一点个人认为比较难理解的知识,在这里拿出来看一下:
1 $("#panel").hover(function() { 2 $(this).stop.animate({ // 如果在此时触发了光标移出的事件 3 height: "150" // 将执行下面的动画 4 // 而非光标移出事件中的动画 5 }, 200).animate({ 6 width: "300" 7 }, "300") 8 }, function() { // 以下是光标移出事件的动画代码段,将不会被执行 9 $(this).stop.animate({ 10 height: "22" 11 }, 200).animate({ 12 width: "60" 13 }, 300) 14 })
解决方法:
1 $("#panel").hover(function(true) { // 函数第一个参数设置为true 2 $(this).stop.animate({ 3 height: "150" 4 5 }, 200).animate({ 6 width: "300" 7 }, "300") 8 }, function(true) { 9 $(this).stop.animate({ 10 height: "22" 11 }, 200).animate({ 12 width: "60" 13 }, 300) 14 })
浙公网安备 33010602011771号