当前位置:嗨网首页>书籍在线阅读

27-解决方案

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

7.6.2 解决方案

在这个解决方案中,我打算包含一些调试信息,所以我包含了一个ID为 debug<div> 元素,并将在这个元素上附加日志信息,帮助我们查看发生的情况。

将使用自定义jQuery选择器 :animated 测试动画是否运行:

$(document).ready(function () {
  var speed = 100;
  $('#animate').click(function () {
   $('.box')
     .filter(':not(:animated)')
     .animate({ marginLeft: −10 }, speed, function () {
      $('#debug').append('<p>Starting animation.<p>');
     })
     .animate({ marginLeft: 10 }, speed)
     .animate({ marginLeft: −10}, speed)
     .animate({ marginLeft: 10 }, speed)
     .animate({ marginLeft: −10}, speed)
     .animate({ marginLeft: 10 }, speed)
     .animate({ marginLeft: 0}, speed, function () {
      $('#debug').append('<p>Finished animation.</p>');
     }); //长方法链结束
   });
  });