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