我想让这个动画一直进行下去,各位大侠,能不能?

ZiSheng 2011-07-13 03:33:27

<html>
<head>
<title>SetTimeout</title>
<style type="text/css">
div{
height:200px;
width:600px;
background-color:#CCCCCC;
}
#test1
{
background:#99CC00;
position:fixed;
left:300px;
border:1px solid red;
filter:alpha(opacity=0);
}
</style>
</head>
<body>
<h2>Great Web resources</h2>
<div id="test1"></div>
<button onclick="doSome()">测试</button>
<script language="javascript">
function $(id)
{
return document.getElementById(id);
}
function doSome()
{
this.fadeIn($("test1"));
}

function setOpacity(obj,value)
{
//debugger;
//alert(value);
if(obj.filters)
{
obj.style.filter='alpha(opacity='+value+')';
}
else{
obj.style.opacity=value/100;
}
if(value==100){
fadeOut(obj);
//alert("hah");
}
}

function fadeIn(obj)
{
for(var i=0;i<=100;i+=2)
{
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},(pos+1)*10);
}
)();
//if(i==100){
// fadeOut(obj);
//}
}
}
function fadeOut(obj)
{
for(var i=98;i>=0;i-=2)
{
//alert(Math.abs((i-98)));
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},Math.abs((pos-98))*10);
}
)();
//if(i==0){
// fadeIn(obj);
//}
}
}
</script>


</body>
</html>

...全文
180 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZiSheng 2011-07-16
  • 打赏
  • 举报
回复
我终于明白了,呵呵。
ZiSheng 2011-07-14
  • 打赏
  • 举报
回复
如果去掉pos变量的定义就没有了淡入淡出的效果。
knightzhuwei 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zisheng 的回复:]

引用 9 楼 confidenceyu 的回复:
你试下不就知道了

这里可能涉及到闭包的问题,有些不是很清楚,不是简单的试一下你就明白了。
[/Quote]
pos后面要用 你不定义怎么用?
ZiSheng 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 knightzhuwei 的回复:]
引用 12 楼 zisheng 的回复:

如果去掉pos变量的定义就没有了淡入淡出的效果。

报错了当然就没有效果了
[/Quote]
兄弟,你能不能测试下,再下结论!!!
knightzhuwei 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zisheng 的回复:]

如果去掉pos变量的定义就没有了淡入淡出的效果。
[/Quote]
报错了当然就没有效果了
ZiSheng 2011-07-13
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 confidenceyu 的回复:]
你试下不就知道了
[/Quote]
这里可能涉及到闭包的问题,有些不是很清楚,不是简单的试一下你就明白了。
confidenceyu 2011-07-13
  • 打赏
  • 举报
回复
你试下不就知道了
ZiSheng 2011-07-13
  • 打赏
  • 举报
回复
var pos=i;
这个变量定义与不定义,有什么区别?
挨踢直男 2011-07-13
  • 打赏
  • 举报
回复
<html>
<head>
<title>SetTimeout</title>
<style type="text/css">
div{
height:200px;
width:600px;
background-color:#CCCCCC;
}
#test1
{
background:#99CC00;
position:fixed;
left:300px;
border:1px solid red;
filter:alpha(opacity=0);
}
</style>
</head>
<body>
<h2>Great Web resources</h2>
<div id="test1"></div>
<button onclick="doSome()">测试</button>
<script language="javascript">
function $(id)
{
return document.getElementById(id);
}
function doSome()
{
this.fadeIn($("test1"));
setTimeout(doSome,3000)//刚才加错地方了
}

function setOpacity(obj,value)
{
//debugger;
//alert(value);
if(obj.filters)
{
obj.style.filter='alpha(opacity='+value+')';
}
else{
obj.style.opacity=value/100;
}
if(value==100){
fadeOut(obj);
//alert("hah");
}
}

function fadeIn(obj)
{
for(var i=0;i<=100;i+=2)
{
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},(pos+1)*10);
}
)();
//if(i==100){
// fadeOut(obj);
//}
}
}
function fadeOut(obj)
{
for(var i=98;i>=0;i-=2)
{
//alert(Math.abs((i-98)));
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},Math.abs((pos-98))*10);
}
)();
//if(i==0){
// fadeIn(obj);
//}
}
}
</script>


</body>
</html>
挨踢直男 2011-07-13
  • 打赏
  • 举报
回复
<html>
<head>
<title>SetTimeout</title>
<style type="text/css">
div{
height:200px;
width:600px;
background-color:#CCCCCC;
}
#test1
{
background:#99CC00;
position:fixed;
left:300px;
border:1px solid red;
filter:alpha(opacity=0);
}
</style>
</head>
<body>
<h2>Great Web resources</h2>
<div id="test1"></div>
<button onclick="doSome()">测试</button>
<script language="javascript">
function $(id)
{
return document.getElementById(id);
setTimeout(doSome,3000)
}
function doSome()
{
this.fadeIn($("test1"));
}

function setOpacity(obj,value)
{
//debugger;
//alert(value);
if(obj.filters)
{
obj.style.filter='alpha(opacity='+value+')';
}
else{
obj.style.opacity=value/100;
}
if(value==100){
fadeOut(obj);
//alert("hah");
}
}

function fadeIn(obj)
{
for(var i=0;i<=100;i+=2)
{
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},(pos+1)*10);
}
)();
//if(i==100){
// fadeOut(obj);
//}
}
}
function fadeOut(obj)
{
for(var i=98;i>=0;i-=2)
{
//alert(Math.abs((i-98)));
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},Math.abs((pos-98))*10);
}
)();
//if(i==0){
// fadeIn(obj);
//}
}
}
</script>


</body>
</html>
ZiSheng 2011-07-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xuexiaodong2009 的回复:]
应该没为题啊
[/Quote]
有问题,代码执行下就知道了。
z13962603112 2011-07-13
  • 打赏
  • 举报
回复
没问提吧
ZiSheng 2011-07-13
  • 打赏
  • 举报
回复
var pos=i;
这个变量定义与不定义,有什么区别?
xuexiaodong2009 2011-07-13
  • 打赏
  • 举报
回复
应该没为题啊
knightzhuwei 2011-07-13
  • 打赏
  • 举报
回复

<html>
<head>
<title>SetTimeout</title>
<style type="text/css">
div{
height:200px;
width:600px;
background-color:#CCCCCC;
}
#test1
{
background:#99CC00;
position:fixed;
left:300px;
border:1px solid red;
filter:alpha(opacity=0);
}
</style>
</head>
<body>
<h2>Great Web resources</h2>
<div id="test1"></div>
<button onclick="doSome()">测试</button>
<script language="javascript">
function $(id)
{
return document.getElementById(id);
}
function doSome()
{
this.fadeIn($("test1"));
}

function setOpacity(obj,value)
{
//debugger;
//alert(value);
if(obj.filters)
{
obj.style.filter='alpha(opacity='+value+')';
}
else{
obj.style.opacity=value/100;
}
if(value==100){
fadeOut(obj);
//alert("hah");
}
}

function fadeIn(obj)
{
for(var i=0;i<=100;i+=2)
{
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},(pos+1)*10);
}
)();
//if(i==100){
// fadeOut(obj);
//}
}
}
function fadeOut(obj)
{
for(var i=98;i>=0;i-=2)
{
//alert(Math.abs((i-98)));
(function(){
var pos=i;
setTimeout(function(){setOpacity(obj,pos);},Math.abs((pos-98))*10);
}
)();
//if(i==0){
// fadeIn(obj);
//}
}
setTimeout(function(){fadeIn(obj);},Math.abs((99))*10);
}
</script>


</body>
</html>


87,909

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧