<!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>js淡入淡出的图片</title>
<style>
#img{display:block;margin:0 auto; opacity:0.3; filter:alpha(opacity=30); width:200px; height:300px;}
</style>
<script>
window.onload=function(){
var oImg=document.getElementById('img');
var iTimer=0;
oImg.onmouseover=function(){
startMove(this,100,10);
}
oImg.onmouseout=function(){
startMove(this,30,-10);
}
function startMove(obj, iTarget, iSpeed) {
clearInterval(iTimer);
var iCur=0;
iTimer = setInterval(function() {
iCur=Math.round(css(obj,'opacity')*100);
if (iCur == iTarget) {
clearInterval(iTimer);
} else {
obj.style.opacity=(iCur+iSpeed)/100;
obj.style.filter='alpha(opacity='+(iCur+iSpeed)+')'; //加括号防止转换成字符串
} }, 30);
} function css(obj,attr){ //获取元素的css任何属性
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}}
</script>
</head>
<body>
<img src='cat.jpg' id='img'/> </body>
</html>

最新文章

  1. ssh自动输入密码脚本 切换目录脚本
  2. 【转】MySQL数据丢失讨论
  3. The JSP specification requires that an attribute name is preceded by whitespace
  4. freemarker初级教程(一)
  5. 跑PIN码破解无线网络WIFI密码的原理分析(转)
  6. python学习笔记-day4笔记 常用内置函数与装饰器
  7. Camel In Action 阅读笔记 第一章 认识Camel 1.1 Camel 介绍
  8. IP地址接口小结
  9. 使用Swiper轮播插件引起的探索
  10. go os/exec执行外部程序
  11. Linux下 nfs部署
  12. Androi:ViewPager
  13. linux 个人配置记录
  14. MySQL是如何利用索引的
  15. 在selenium中使用css选择器进行元素定位
  16. frame shiro 概述
  17. elasticSearch curl 语法总结
  18. VirtualBOX启动错误the vm session was closed before any attempt to power it on解决办法
  19. Java类的设计----Object 类
  20. Bash to check SSL cert expired

热门文章

  1. inline-block
  2. Java常量字符串String理解
  3. 解决ubuntu下安装phpmyadmin访问不了的问题
  4. Spark SQL Thrift Server 配置 Kerberos身份认证和权限管理
  5. java 读写JSON(一)
  6. Flex Builder读书笔记(一)
  7. 数据库基础知识(1)--数据库php连接
  8. 跨域之-jquery操作
  9. 列表框QListWidget类
  10. [zz] 混合高斯模型 Gaussian Mixture Model