星空网 > 软件开发 > Java

animate()方法以一次设置多个属性

animate()方法以一次设置多个属性:
此方法可以为匹配元素创建自定义动画,例如可以将一个div的宽度设置为200px,代码实例如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">div{ width:150px; height:150px; background-color:green;}</style><script type="text/javascript" src='/images/loading.gif' data-original="mytest/jQuery/jquery-1.8.3.js"></script><script type="text/javascript"> $(document).ready(function(){  $("button").click(function(){   $("div").animate({"width":"200px"})  }) }); </script></head><body><div></div><button>点击设置</button></body></html>

以上代码成功将div的宽度设置为200px,但是实际应用中往往需要同时设置匹配元素的多个属性值。代码实例如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">div{ width:150px; height:150px; background-color:green;}</style><script type="text/javascript" src='/images/loading.gif' data-original="mytest/jQuery/jquery-1.8.3.js"></script><script type="text/javascript"> $(document).ready(function(){  $("button").click(function(){   $("div").animate({"width":"200px","height":"300px"})  }) }); </script></head><body><div></div><button>点击设置</button></body></html>

以上代码同时设置了div的宽度和高度,方法就是在每一组属性/值对之间添加逗号分隔即可。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=5803

更多内容可以参阅:http://www.softwhy.com/jquery/




原标题:animate()方法以一次设置多个属性

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流