為什么我這個鼠標移上去透明度沒有反應,可以幫我看一下嗎?
<html>
<head>
? ?<meta charset="utf-8">
? ?<title>test</title>
? ?<style>
? ? ? ?div{
? ? ? ? ? ?background:red;
? ? ? ? ? ?width:200px;
? ? ? ? ? ?height:200px;
? ? ? ? ? ?filter:alpha(opacity:30);
? ? ? ? ? ?opacity:0.3;
? ? ? ? ? ?margin:30px;
? ? ? ?}
? ?</style>
? ?<script>
? ?window.onload = function () {
? ? ? ?var div = document.getElementsByTagName("div");
? ? ? ?for(var i=0;i<div.length;i++){
? ? ? ? ? ?div[i].alpha = 30;
? ? ? ? ? ?div[i].timer = null;
? ? ? ? ? ?div[i].onmouseover = function () {
? ? ? ? ? ? ? ?start(this,100);
? ? ? ? ? ?};
? ? ? ? ? ?div[i].onmouseout = function () {
? ? ? ? ? ? ? ?start(this,30);
? ? ? ? ? ?};
? ? ? ?}
? ?};
? ?function start(obj,target){
? ? ? ?var speed = 0;
? ? ? ?clearInterval(obj.timer);
? ? ? ?obj.timer = setInterval(function () {
? ? ? ? ? ?if(obj.alpha > target)
? ? ? ? ? ? ? ?{ speed = -10;}
? ? ? ? ? ?else
? ? ? ? ? ? ? ?{ speed = 10;}
? ? ? ? ? ?if(target == obj.alpha)
? ? ? ? ? ?{clearInterval(obj.timer);}
? ? ? ? ? ?else{
? ? ? ? ? ? ? ? ? ?obj.alpah += speed;
? ? ? ? ? ? ? ? ? ?obj.style.filter = "alpha(opacity:" + obj.alpah + ");";
? ? ? ? ? ? ? ? ? ?obj.style.opacity = obj.alpha/100;
? ? ? ? ? ? ? ?}
? ? ? ?},30);
? ?}
? ?</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
</body>
</html>
2017-01-15
代碼第42、43行,alpha單詞拼寫錯誤:
obj.alpah += speed;
obj.style.filter = "alpha(opacity:" + obj.alpah + ");";