甯繖鐪嬩笅鍝噷鍑洪敊浜嗭紝涓轰粈涔堜笉寰幆锛?/a>

时间:2021-12-24 14:11:44
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css" >

#a{
position:absolute;
top:0px;
left:0px;
width:100px;
height:100px;


}


</style>

<title>excise</title>

<script type="text/javascript">

var speedx=Math.random()*50;
var b=1;
var c=1;

var w=document.body.offsetWidth;
var h=document.body.offsetHeight;

function move(){
var x=document.getElementById("a").style.left;
var y=document.getElementById("a").style.top;
if (parseInt(x)+150>w||parseInt(x)<0){

b=-b;

}
if (parseInt(y)+100>h||parseInt(y)<0){

c=-c;

}

document.getElementById("a").style.left=x+speedx*b;
document.getElementById("a").style.top=y+speedx*c;

setTimeout("move()",500);<!--????????涓轰粈涔??????姝ゅ彞鏈夋棤鎵ц鐨勬晥鏋滈兘涓€鏍?->

}




</script>
</head>

<body onload="move()">

<div id="a"><img src="../image/3.jpg" width="100" heigh="100" /></div>

</body>
</html>

鐜板湪鍦ㄨJS鍋氫釜缁冧範锛岃涓€涓浘鐗囧湪缃戦〉涓婃诞鍔紝閬囧埌杈圭紭鍚庡脊鍥烇紝涓婇潰鐨勪唬鐮佸彲浠ュ疄鐜扮涓€娆′綅缃彉鍔紝浣嗘槸杩炵画鎵ц灏变笉琛屼簡锛岀瓑寰呮寚鐐广€?






5 涓В鍐虫柟妗?/h2>

#1


setTimeout("move()",500); <!--????????涓轰粈涔??????姝ゅ彞鏈夋棤鎵ц鐨勬晥鏋滈兘涓€鏍?-> 
杩欏彞璇濇槸涓嶆槸瑕佹斁鍦▄}澶栭潰锛?
鎴戜篃澶栬銆傘€傘€傚懙鍛点€傚叧娉ㄤ竴涓?

#2


寮曠敤 1 妤?nbsp;sunnxxy 鐨勫洖澶?
setTimeout("move()",500); <!--????????涓轰粈涔??????姝ゅ彞鏈夋棤鎵ц鐨勬晥鏋滈兘涓€鏍?-> 
杩欏彞璇濇槸涓嶆槸瑕佹斁鍦▄}澶栭潰锛?nbsp;
鎴戜篃澶栬銆傘€傘€傚懙鍛点€傚叧娉ㄤ竴涓?

澶栭潰灏变笉缁х画鍙樻洿浣嶇疆浜嗐€?

#3


<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css" >
#a{
position:absolute;
top:0px;
left:0px;
width:100px;
height:100px;}
</style>
<title>excise</title>
<script type="text/javascript">
var speedx=Math.random()*50;
var b=1;
var c=1;
var w=document.body.offsetWidth;
var h=document.body.offsetHeight;
function move(){
var x=document.getElementById("a").style.left;
var y=document.getElementById("a").style.top;
if (parseInt(x)+150>w||parseInt(x)<0){
b=-b;}
if (parseInt(y)+100>h||parseInt(y)<0){
c=-c; }
document.getElementById("a").style.left=x+speedx*b;
document.getElementById("a").style.top=y+speedx*c;
setTimeout("move()",500) } <!--灏辨槸杩欏彞浜嗭紝濂藉儚鏈夋棤閮戒竴鏍?->
</script>
</head>
<body onload="move()">
<div id="a"><img src="../image/3.jpg" width="100" heigh="100" /></div>
</body>
</html>

涓嶅ソ鎰忔€濅粠鏂板彂涓嬶紝杩樹笉澶簡瑙h鍧涚殑鍔熻兘銆?

#4


1銆侀〉闈㈠姞杞芥槸浠庝笂鍒颁笅锛宒ocument瀵硅薄寰梑ody鍔犺浇瀹屾瘯鎵嶆湁鏁堛€?
<title>excise</title>
<script type="text/javascript">        
            var speedx=Math.random()*50;
            var b=1;
            var c=1;            
            var w= document.body.offsetWidth;
            var h= document.body.offsetHeight;

2銆乷ffsetWidth涓嶄竴瀹氭湁杩欎釜灞炴€э紝寰楀吋瀹筩lientWidth
            var w=document.body. offsetWidth;
            var h=document.body. offsetHeight;

3銆乻tyle.left娌℃湁璧嬪€艰繃鍒欐槸绌猴紝璇ュ睘鎬т笉鏄粠鏍峰紡琛ㄩ噷璇诲彇锛岃浆鎹负鏁存暟涓篘aN

鍏朵粬缁嗚妭灏辫嚜宸辩湅浠g爜鍚э細
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css" >
#a{
position:absolute;
top:0px;
left:0px;
width:100px;
height:100px;
}

</style>
<title>excise </title>
<script type="text/javascript">
var speedx = Math.random() * 50;
var b = 1;
var c = 1;

function move(){
var w = document.body.offsetWidth || document.body.clientWidth;
var h = document.body.offsetHeight || document.body.clientHeight;

var x = parseFloat(document.getElementById("a").style.left);
if (isNaN(x)) x = 0;
var y = parseFloat(document.getElementById("a").style.top);
if (isNaN(y)) y = 0;
if (x + speedx * b + 100 > w || x + speedx * b < 0) {
b = -b;
}
if (y + speedx * c + 150 > h || y + speedx * c < 0) {
c = -c;
}
document.getElementById("a").style.left = x + speedx * b + "px";
document.getElementById("a").style.top = y + speedx * c + "px";

setTimeout("move()", 500);
}
</script>
</head>
<body onload="move()">
<div id="a"> <img src="../image/3.jpg" width="100" heigh="100" /> </div>
</body>
</html> 

#5


寮曠敤 4 妤?nbsp;zswang 鐨勫洖澶?
1銆侀〉闈㈠姞杞芥槸浠庝笂鍒颁笅锛宒ocument瀵硅薄寰梑ody鍔犺浇瀹屾瘯鎵嶆湁鏁堛€?nbsp;
<title>excise </title> 
<script type="text/javascript">        
            var speedx=Math.random()*50; 
            var b=1; 
            var c=1;            
            var w=document.body.offsetWidth; 
            var h=document.body.offsetHeight; 

2銆乷ffsetWidth涓嶄竴瀹氭湁杩欎釜灞炴€э紝寰楀吋瀹筩lientWidth 
            var w=docum鈥?

澶劅璋簡锛屾灉鐒跺姩璧锋潵浜嗐€?

#1


setTimeout("move()",500); <!--????????涓轰粈涔??????姝ゅ彞鏈夋棤鎵ц鐨勬晥鏋滈兘涓€鏍?-> 
杩欏彞璇濇槸涓嶆槸瑕佹斁鍦▄}澶栭潰锛?
鎴戜篃澶栬銆傘€傘€傚懙鍛点€傚叧娉ㄤ竴涓?

#2


寮曠敤 1 妤?nbsp;sunnxxy 鐨勫洖澶?
setTimeout("move()",500); <!--????????涓轰粈涔??????姝ゅ彞鏈夋棤鎵ц鐨勬晥鏋滈兘涓€鏍?-> 
杩欏彞璇濇槸涓嶆槸瑕佹斁鍦▄}澶栭潰锛?nbsp;
鎴戜篃澶栬銆傘€傘€傚懙鍛点€傚叧娉ㄤ竴涓?

澶栭潰灏变笉缁х画鍙樻洿浣嶇疆浜嗐€?

#3


<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css" >
#a{
position:absolute;
top:0px;
left:0px;
width:100px;
height:100px;}
</style>
<title>excise</title>
<script type="text/javascript">
var speedx=Math.random()*50;
var b=1;
var c=1;
var w=document.body.offsetWidth;
var h=document.body.offsetHeight;
function move(){
var x=document.getElementById("a").style.left;
var y=document.getElementById("a").style.top;
if (parseInt(x)+150>w||parseInt(x)<0){
b=-b;}
if (parseInt(y)+100>h||parseInt(y)<0){
c=-c; }
document.getElementById("a").style.left=x+speedx*b;
document.getElementById("a").style.top=y+speedx*c;
setTimeout("move()",500) } <!--灏辨槸杩欏彞浜嗭紝濂藉儚鏈夋棤閮戒竴鏍?->
</script>
</head>
<body onload="move()">
<div id="a"><img src="../image/3.jpg" width="100" heigh="100" /></div>
</body>
</html>

涓嶅ソ鎰忔€濅粠鏂板彂涓嬶紝杩樹笉澶簡瑙h鍧涚殑鍔熻兘銆?

#4


1銆侀〉闈㈠姞杞芥槸浠庝笂鍒颁笅锛宒ocument瀵硅薄寰梑ody鍔犺浇瀹屾瘯鎵嶆湁鏁堛€?
<title>excise</title>
<script type="text/javascript">        
            var speedx=Math.random()*50;
            var b=1;
            var c=1;            
            var w= document.body.offsetWidth;
            var h= document.body.offsetHeight;

2銆乷ffsetWidth涓嶄竴瀹氭湁杩欎釜灞炴€э紝寰楀吋瀹筩lientWidth
            var w=document.body. offsetWidth;
            var h=document.body. offsetHeight;

3銆乻tyle.left娌℃湁璧嬪€艰繃鍒欐槸绌猴紝璇ュ睘鎬т笉鏄粠鏍峰紡琛ㄩ噷璇诲彇锛岃浆鎹负鏁存暟涓篘aN

鍏朵粬缁嗚妭灏辫嚜宸辩湅浠g爜鍚э細
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css" >
#a{
position:absolute;
top:0px;
left:0px;
width:100px;
height:100px;
}

</style>
<title>excise </title>
<script type="text/javascript">
var speedx = Math.random() * 50;
var b = 1;
var c = 1;

function move(){
var w = document.body.offsetWidth || document.body.clientWidth;
var h = document.body.offsetHeight || document.body.clientHeight;

var x = parseFloat(document.getElementById("a").style.left);
if (isNaN(x)) x = 0;
var y = parseFloat(document.getElementById("a").style.top);
if (isNaN(y)) y = 0;
if (x + speedx * b + 100 > w || x + speedx * b < 0) {
b = -b;
}
if (y + speedx * c + 150 > h || y + speedx * c < 0) {
c = -c;
}
document.getElementById("a").style.left = x + speedx * b + "px";
document.getElementById("a").style.top = y + speedx * c + "px";

setTimeout("move()", 500);
}
</script>
</head>
<body onload="move()">
<div id="a"> <img src="../image/3.jpg" width="100" heigh="100" /> </div>
</body>
</html> 

#5


寮曠敤 4 妤?nbsp;zswang 鐨勫洖澶?
1銆侀〉闈㈠姞杞芥槸浠庝笂鍒颁笅锛宒ocument瀵硅薄寰梑ody鍔犺浇瀹屾瘯鎵嶆湁鏁堛€?nbsp;
<title>excise </title> 
<script type="text/javascript">        
            var speedx=Math.random()*50; 
            var b=1; 
            var c=1;            
            var w=document.body.offsetWidth; 
            var h=document.body.offsetHeight; 

2銆乷ffsetWidth涓嶄竴瀹氭湁杩欎釜灞炴€э紝寰楀吋瀹筩lientWidth 
            var w=docum鈥?

澶劅璋簡锛屾灉鐒跺姩璧锋潵浜嗐€?