js写一个图片淡入淡出!
js写一个图片淡入淡出,但是不知下面代码那有错误,执行后浏览器里没有任何变化,找不到原因,往高手帮忙!谢谢!<!DOCTYPEhtmlPUBLIC"-//W3C//DTD...
js写一个图片淡入淡出,但是不知下面代码那有错误,执行后浏览器里没有任何变化,找不到原因,往高手帮忙!谢谢!
<!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=gb2312" />
<title>淡入淡出</title>
<style>
#div1{ height:200px; width:200px; background:red; filter:alpha(opacity:30); opacity:0.3;}
</style>
<script>
window.onload=function(){
var timer=null;
var oDiv=document.getElementById('div1');
var alpha=30;
oDiv.onmouseover=function(){
show(100);
}
oDiv.onmouseout=function(){
show(30);
}
function show(Mm){
clearInterval(timer);
var oDiv=document.getElementById('div1');
var speed=null;
if(alpha<Mm){
speed=10;
}
else{
speed=-10;
}
timer=setInterval(function(){
if(alpha==Mm)
{
clearInterval(timer);
}
else
{
alpha+=speed;
oDiv.style.filter='alpha(opacity:'+alpha')';
oDiv.style.opacity=alpha/100;
}
},30);}
}
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html> 展开
<!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=gb2312" />
<title>淡入淡出</title>
<style>
#div1{ height:200px; width:200px; background:red; filter:alpha(opacity:30); opacity:0.3;}
</style>
<script>
window.onload=function(){
var timer=null;
var oDiv=document.getElementById('div1');
var alpha=30;
oDiv.onmouseover=function(){
show(100);
}
oDiv.onmouseout=function(){
show(30);
}
function show(Mm){
clearInterval(timer);
var oDiv=document.getElementById('div1');
var speed=null;
if(alpha<Mm){
speed=10;
}
else{
speed=-10;
}
timer=setInterval(function(){
if(alpha==Mm)
{
clearInterval(timer);
}
else
{
alpha+=speed;
oDiv.style.filter='alpha(opacity:'+alpha')';
oDiv.style.opacity=alpha/100;
}
},30);}
}
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html> 展开
1个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>淡入淡出</title>
<style>
#div1 {
height: 200px;
width: 200px;
background: red;
filter: alpha(opacity:30);
opacity: 0.3;
}
</style>
<script>
window.onload = function() {
var timer = null;
var oDiv = document.getElementById('div1');
var alpha = 30;
oDiv.onmouseover = function() {
show(100);
}
oDiv.onmouseout = function() {
show(30);
}
function show(Mm) {
clearInterval(timer);
var oDiv = document.getElementById('div1');
var speed = null;
if (alpha < Mm) {
speed = 10;
}
else {
speed = -10;
}
timer = setInterval(function() {
if (alpha == Mm)
{
clearInterval(timer);
}
else
{
alpha += speed;
oDiv.style.filter = 'alpha(opacity:' + alpha + ')';
oDiv.style.opacity = alpha / 100;
}
}, 30);
}
}
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html>
追问
我对比了一下,你写的跟我的一样,为什么我的就运行不出来呢,你改了哪里?
追答
'alpha(opacity:' + alpha + ')';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询