动态V字布局
来源:互联网 发布:网络上认识了你歌曲 编辑:程序博客网 时间:2024/04/29 07:21
先瞄一眼动态图,点击按钮的效果:
废话不多说,开始鲁代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style>*{margin:0;padding:0;}div {width:100px;height:100px;line-height:100px;border:1px solid black;position:absolute;left:0;top:0;text-align:center;font-size:30px;}</style><script>window.onload = function () { var oBtn = document.getElementById('btn1'); var aDiv = document.getElementsByTagName('div'); // 自动添加五个div for ( var i = 0; i < 5; i++ ) { var newDiv = document.createElement('div'); newDiv.innerHTML = i; newDiv.style.background = 'red'; newDiv.style.display = 'none'; document.body.appendChild(newDiv); } var len = aDiv.length; var fnName = [toTop,toRight,toBottom,toLeft]; var index = 0; // 0,1,2,3 => 上 右 下 左 // 点击按钮 依次为上 右 下 左 oBtn.onclick = function () { fnName[index++](); if (index === 4) index = 0; } function toTop() { // 上 => ^ for ( var j = 0; j < len; j++ ) { aDiv[j].style.left = j * 100 + 100 + 'px'; aDiv[j].style.top = 100 * (j < 3 ? 2 - j : j - 2) + 100 + 'px'; aDiv[j].style.display = 'block'; } } function toRight() { // 上 => > for ( var j = 0; j < len; j++ ) { aDiv[j].style.top = j * 100 + 100 + 'px'; aDiv[j].style.left = 100 * (j < 3 ? j : 4 - j) + 100 + 'px'; } } function toBottom() { // 上 => v for ( var j = 0; j < len; j++ ) { aDiv[j].style.left = j * 100 + 100 + 'px'; aDiv[j].style.top = 100 * (j < 3 ? j : 4 - j) + 100 + 'px'; } } function toLeft() { // 上 => < for ( var j = 0; j < len; j++ ) { aDiv[j].style.top = j * 100 + 100 + 'px'; aDiv[j].style.left = 100 * (j < 3 ? 2 - j : j - 2) + 100 + 'px'; } }}</script></head><body><input type="button" id="btn1" value="按钮"/></body></html>
0 0
- 动态V字布局
- 动态视图v$sysstat
- 动态布局
- 动态布局
- 动态布局
- 动态布局
- 动态性能视图v$mystat,v$sesstat,v…
- 动态性能视图v$mystat,v$sesstat,v…
- Oracle的v$动态视图
- 动态性能视图:V$FILESTAT
- 动态性能表v$db_object_cache
- oracle-动态性能(V$)视图
- 动态性能表v$db_object_cache
- oracle 动态性能(V$)视图
- 动态性能视图 V$SESSION_LONGOPS
- vue v-model 动态生成
- HashMap v.s. 动态规划
- Android 动态布局 (代码布局)
- string与stringBuffer之间的区别
- Brewing ImageNet
- Linux下C库学习 - assert.h
- 深坑: some logs have been lost
- 《JS高程(3)》-第6章笔记(01)
- 动态V字布局
- jQuery技术解密五
- spring-boot 集成spring-session redis
- android_46_BroadcastReceiver_短信拦截
- uoj思维题目
- 关于android layout布局中的tools属性
- css常用
- 在java文件中设置文字颜色:setTextColor()
- Nginx配置文件详解