<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>title</title>
<style>
div{
width: 300px;
height: 200px;
background-color: hotpink;
}
</style>
</head>
<body>
<div id="dv"></div>
<input type="button" value="漸變" id="btn"/>
<script src="common.js"></script>
<script>
my$("btn").onclick=function () {
var opacity=1;
//按鈕的點選事件
var timeId=setInterval(function () {
//透明化了
opacity=opacity-0.1;
if(opacity<=0){
clearInterval(timeId);//清理定時器
}
//設定div的透明度
my$("dv").style.opacity=opacity;
},200);
};
</script>
</body>
</html>