求大神帮忙改下js 弄成循环效果

qingwadaxia_1 2017-11-28 05:09:19
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>

<meta content="yes" name="apple-mobile-web-app-capable">

</head>
<style type="text/css">
*{padding:0;margin:0;}
#cc{
background:#ccc;
width:200px;
height:200px;
position:absolute;
bottom:0;
right:0;
white-space:nowrap;
overflow:hidden;
display:none;
}
</style>
<body style="height:2000px;">

<div id="cc">111</div>


<script type="text/javascript">
var cc = document.getElementById("cc");
var ys = window.getComputedStyle?window.getComputedStyle(cc,""):cc.currentStyle;
var hqc = parseInt(ys.width);  
var hqg = parseInt(ys.height);
var sc = document.documentElement.clientWidth;
var sg = document.documentElement.clientHeight;
var jsr = Math.ceil((sc - hqc)/2);
var jsx = Math.ceil((sg - hqg)/2);
var ys = 5;
var yd = ys * jsx / jsr ;
var time = null;
var bottom = 0;
var right = 0;

setTimeout(function(){
cc.style.display = "block";
time = setInterval(function zzz(){
right += ys;
bottom += yd;
cc.style.right = right + "px";
cc.style.bottom = bottom + "px";
if(right>=jsr){
clearInterval(time);
cc.onclick=function(){
ys = -ys;
yd = -yd;
setTimeout(function(){
time = setInterval(zzz,10);
},0)
}
}
if(right == 0 || bottom == 0){
clearInterval(time);
cc.style.right = 0;
cc.style.bottom = 0;
cc.style.display = "none";
}
},10);
},3000);
</script>



</body>
</html>

这个js 是一个3秒后, div斜向移动到网页正中间的效果, 点击div的时候, 再斜向退回去,然后消失, 我现在的需求是两种:

一种是:想把它改成斜向消失6秒之后 ,又会再次斜向出现在正中间,点击div之后,又会斜向消失,然后6秒又出现,一直循环

第二种是: 斜向出现在正中间之后,不需要点击, 等2秒, 又斜向消失, 然后6秒之后 又斜向出现,2秒后又斜向消失,一直自动循环
...全文
155 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qingwadaxia_1 2017-11-28
  • 打赏
  • 举报
回复
引用 2 楼 jslang 的回复:
第二种

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title></title>
 
<meta content="yes" name="apple-mobile-web-app-capable">

 </head>
 <style type="text/css">
	*{padding:0;margin:0;}
     #cc{
         background:#ccc;
		 width:200px;
		 height:200px;
		 position:absolute;
		 bottom:0;
		 right:0;
		 white-space:nowrap;
		 overflow:hidden;
		 display:none;
     }
 </style>
 <body style="height:2000px;">

<div id="cc">111</div>


<script type="text/javascript">
	var cc = document.getElementById("cc");
	var ys = window.getComputedStyle?window.getComputedStyle(cc,""):cc.currentStyle;
	var hqc = parseInt(ys.width);  
	var hqg = parseInt(ys.height);
	var sc = document.documentElement.clientWidth;
	var sg = document.documentElement.clientHeight;
	var jsr = Math.ceil((sc - hqc)/2);
	var jsx = Math.ceil((sg - hqg)/2);
	var ys = 5;
	var yd = ys * jsx / jsr ;
	var time = null;
	var bottom = 0;
	var right = 0;

		setTimeout(function aaa(){
			cc.style.display = "block";
			time = setInterval(function zzz(){
				right += ys;
				bottom += yd;
				cc.style.right = right + "px";
				cc.style.bottom = bottom + "px";
				if(right>=jsr){
					clearInterval(time);
					setTimeout(function(){
						ys = -ys;
						yd = -yd;
						time = setInterval(zzz,10);
					},2000)
				}
				if(right == 0 || bottom == 0){
					clearInterval(time);
					cc.style.right = 0;
					cc.style.bottom = 0;
					cc.style.display = "none";
					ys = -ys;
					yd = -yd;
					setTimeout(aaa, 6000);
				}
			},10);
		},3000);
</script>



 </body>
</html>
真大神,谢谢您了!!
天际的海浪 2017-11-28
  • 打赏
  • 举报
回复
第二种

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title></title>
 
<meta content="yes" name="apple-mobile-web-app-capable">

 </head>
 <style type="text/css">
	*{padding:0;margin:0;}
     #cc{
         background:#ccc;
		 width:200px;
		 height:200px;
		 position:absolute;
		 bottom:0;
		 right:0;
		 white-space:nowrap;
		 overflow:hidden;
		 display:none;
     }
 </style>
 <body style="height:2000px;">

<div id="cc">111</div>


<script type="text/javascript">
	var cc = document.getElementById("cc");
	var ys = window.getComputedStyle?window.getComputedStyle(cc,""):cc.currentStyle;
	var hqc = parseInt(ys.width);  
	var hqg = parseInt(ys.height);
	var sc = document.documentElement.clientWidth;
	var sg = document.documentElement.clientHeight;
	var jsr = Math.ceil((sc - hqc)/2);
	var jsx = Math.ceil((sg - hqg)/2);
	var ys = 5;
	var yd = ys * jsx / jsr ;
	var time = null;
	var bottom = 0;
	var right = 0;

		setTimeout(function aaa(){
			cc.style.display = "block";
			time = setInterval(function zzz(){
				right += ys;
				bottom += yd;
				cc.style.right = right + "px";
				cc.style.bottom = bottom + "px";
				if(right>=jsr){
					clearInterval(time);
					setTimeout(function(){
						ys = -ys;
						yd = -yd;
						time = setInterval(zzz,10);
					},2000)
				}
				if(right == 0 || bottom == 0){
					clearInterval(time);
					cc.style.right = 0;
					cc.style.bottom = 0;
					cc.style.display = "none";
					ys = -ys;
					yd = -yd;
					setTimeout(aaa, 6000);
				}
			},10);
		},3000);
</script>



 </body>
</html>
天际的海浪 2017-11-28
  • 打赏
  • 举报
回复
第一种

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title></title>
 
<meta content="yes" name="apple-mobile-web-app-capable">

 </head>
 <style type="text/css">
	*{padding:0;margin:0;}
     #cc{
         background:#ccc;
		 width:200px;
		 height:200px;
		 position:absolute;
		 bottom:0;
		 right:0;
		 white-space:nowrap;
		 overflow:hidden;
		 display:none;
     }
 </style>
 <body style="height:2000px;">

<div id="cc">111</div>


<script type="text/javascript">
	var cc = document.getElementById("cc");
	var ys = window.getComputedStyle?window.getComputedStyle(cc,""):cc.currentStyle;
	var hqc = parseInt(ys.width);  
	var hqg = parseInt(ys.height);
	var sc = document.documentElement.clientWidth;
	var sg = document.documentElement.clientHeight;
	var jsr = Math.ceil((sc - hqc)/2);
	var jsx = Math.ceil((sg - hqg)/2);
	var ys = 5;
	var yd = ys * jsx / jsr ;
	var time = null;
	var bottom = 0;
	var right = 0;

		setTimeout(function aaa(){
			cc.style.display = "block";
			time = setInterval(function zzz(){
				right += ys;
				bottom += yd;
				cc.style.right = right + "px";
				cc.style.bottom = bottom + "px";
				if(right>=jsr){
					clearInterval(time);
					cc.onclick=function(){
						ys = -ys;
						yd = -yd;
						setTimeout(function(){
							time = setInterval(zzz,10);
						},0)
					}
				}
				if(right == 0 || bottom == 0){
					clearInterval(time);
					cc.style.right = 0;
					cc.style.bottom = 0;
					cc.style.display = "none";
					ys = -ys;
					yd = -yd;
					setTimeout(aaa, 6000);
				}
			},10);
		},3000);
</script>



 </body>
</html>

87,994

社区成员

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

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