DIV宽度自动缓慢变化
2016-07-25 21:30
387 查看
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>宽度缓慢变化</title> <style> #chg { width: 200px; height: 120px; background-color: #390; margin: auto; } #btn { width: 200px; height: 30px; background-color: #000; margin: auto; display: block; cursor: pointer; color: #FFF; font-size: 12px; text-align: center; line-height: 30px; font-weight: bolder; } </style> </head> <body> <div id="chg"></div><br /> <div id="btn" onclick="$d3()">展开</div> </body> </html> <script> function $d1() { var l = document.getElementById("chg"); var w = l.offsetWidth; var maxw = 500; function chgws() { w += 1; if(w >= maxw) { l.style.width = '500px'; clearInterval(iIntervalId); } else { l.style.width = w + 'px'; } } iIntervalId = setInterval(chgws, 10); } function $d2() { var m = document.getElementById("chg"); var n = m.offsetWidth; var maxw = 500; function chgwh() { n -= 1; if(n <= 200) { m.style.width = '200px'; clearInterval(iIntervalId); } else { m.style.width = n + 'px'; } } iIntervalId = setInterval(chgwh, 10); } function $d3() { var q = document.getElementById("chg"); var chgb = document.getElementById('btn'); if(chgb.innerHTML == "展开") { chgb.innerHTML = "收缩"; $d1(); } else { chgb.innerHTML = "展开"; $d2(); } } </script>
相关文章推荐
- jmeter压力测试的简单实例+badboy脚本录制
- Educational Codeforces Round 13 E 状压dp
- form表单的提交方式:submit和button.
- eclipse常用快捷键汇总
- robots | 优化你的wordpress博客
- [转]怎么看时序图--nand flash的读操作详解
- HDOJ 1873 看病要排队(优先队列)
- 大话设计模式22----合成/聚合复用原则 & 桥接模式
- poj1416 Shredding Company
- DrawerLayout:左右侧拉菜单
- Iptables总结
- bootstrap table学习小记
- poj1416 Shredding Company
- aliyun阿里云Maven仓库地址——加速你的maven构建
- HDU1542——Atlantis(扫描线,线段树,矩形面积并,离散化)
- 寻找最大的列号
- poj1363Rails
- Maven使用详解
- memcache统计同一数据搜索次数,设置缓存
- Maven使用详解