為什么沒(méi)效果呢
<!doctype?html>
<html>
<head>
<meta?charset="utf-8">
<title>無(wú)標(biāo)題文檔</title>
<style?type="text/css">
body?{margin:0;}
.divs?{
width:200px;
height:200px;
background:?red;
opacity:0.3;
filter:alpha(opacity:30);
cursor:pointer;
}
</style>
<script?type="text/javascript">
window.onload?=?function(){
var?timer?=?null;
var?apa?=?30;
var?oDiv=document.getElementsByClassName("divs")[0];
function?Alphas?(iTarget){
clearInterval(timer);
var?Speed?=?0;
if(iTarget>apa){
Speed?=?10;
}else?if(iTarget<apa){
Speed?=?-10;
}
timer?=?setInterval(function(){
if(apa?==iTarget){
clearInterval(timer)
}else{
apa+=Speed;
oDiv.style.opacity?=?apa/100;
oDiv.style.filter="alpha(opacity:"+apa+")";
//console.log(apa);
}
},20)
oDiv.onmouseover=function(){
Alphas(100);
}
oDiv.onmouseout=function(){
Alphas(30);
}
}
}
</script>
</head>
<body>
<div?class="divs"></div>
</body>
</html>為什么移入移出都沒(méi)效果呢?怎么也找不到問(wèn)題在哪 也不報(bào)錯(cuò)
2016-07-11
挺多錯(cuò)誤的, 最致命的錯(cuò)誤是把所有的定義函數(shù)放在widow.onload下了,其次定時(shí)器也錯(cuò)了?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無(wú)標(biāo)題文檔</title>
<style type="text/css">
body {margin:0;}
#divs {
? ? width:200px;
? ? height:200px;
? ? background:red;
? ? opacity:0.3;
? ? filter:alpha(opacity:30);
? ? cursor:pointer;
? ? }
</style>
<script type="text/javascript">
window.onload = function(){
? ? var oDiv=document.getElementById('divs');
oDiv.onmouseover=function(){
? ? ? ? Alphas(100); ? ? ??
? ? }
? ? oDiv.onmouseout=function(){
? ? ? ? Alphas(30);
? ? } ?
}
? ?var timer = null;
? ? var apa = 30;
? ? function Alphas (iTarget){
? ? ? ?clearInterval(timer);
var oDiv=document.getElementById('divs');
? ? ? ? timer= setInterval(function(){ ?//定時(shí)器
var Speed = 0;
? ? ? ? ? ? if(iTarget>apa){
? ? ? ? ? ? ? ? Speed = 10;
? ? ? ? ? ? }else if(iTarget<apa){
? ? ? ? ? ? ? ? Speed = -10;?
? ? ? ? ? ? }
? ? ? ? ? ? if(apa ==iTarget){
? ? ? ? ? ? ? ? clearInterval(timer) ??
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? apa+=Speed;
? ? ? ? ? ? ? ? oDiv.style.opacity = apa/100;
? ? ? ? ? ? ? ? oDiv.style.filter="alpha(opacity:"+apa+")";
? ? ? ? ? ? ? ? //console.log(apa);
? ? ? ? ? ? }
? ? ? ? },20)
? ?
? ? }
?
</script>
</head>
?
<body>
<div id="divs"></div>
</body>
</html>
2016-10-16
var?oDiv=document.getElementsByClassName("divs")[0];你這句話錯(cuò)了