js hover放大效果
2016-12-16 00:00
176 查看
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Examples</title> <meta name="description" content=""> <meta name="keywords" content=""> <style> * { margin: 0; padding: 0; } ul { width: 400px; position: relative; margin: 100px auto; } li { width: 100px; height: 100px; background: red; margin: 10px; float: left; list-style: none; z-index: 1 } </style> <script> window.onload = function() { var oUl = document.getElementById("test"); var oLi = oUl.getElementsByTagName('li'); var curZIndex = 2; for (var i = 0; i < oLi.length; i++) { oLi[i].style.left = oLi[i].offsetLeft + "px"; oLi[i].style.top = oLi[i].offsetTop + "px"; } for (var i = 0; i < oLi.length; i++) { oLi[i].style.position = "absolute"; oLi[i].style.margin = 0 oLi[i].onmouseover = function() { this.style.zIndex = curZIndex++; this.style.width = 150 + "px"; this.style.height = 150 + "px"; this.style.marginLeft = -25 + "px"; this.style.marginTop = -25 + "px"; this.style.backgroundColor = "blue"; } oLi[i].onmouseout = function() { this.style.width = 100 + "px"; this.style.height = 100 + "px"; this.style.marginLeft = 0 + "px"; this.style.marginTop = 0 + "px"; this.style.backgroundColor = "red"; } } } </script> </head> <body> <ul id="test"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </body> </html>
相关文章推荐
- 递归 与 js 对象的引用
- 关于javascript延迟加载图片
- JS作用域概念-预解析规则
- JS字符串操作大全
- js微博发布框
- 全面理解面向对象的 JavaScript
- 判断JS对象是否拥有某属性的方法举例
- js 组件的写法
- js上传图片并预览
- JS当前日期相加相减
- 100个直接可以拿来用的JavaScript实用功能代码片段
- JS切换卡效果
- 由数组随机化排序引出的对于js中sort()方法的理解分析
- 跳转页面的几种方法
- js基础之 正则表达式
- JavaScript跨域总结与解决办法
- 很奇怪的问题。点击button会自动刷新页面?
- fastjson
- 深入理解js闭包
- JavaScript继承方式详解