BOM
BOM定义
<script type
="text/javascript">
console
.log(window
);
console
.log(typeof window
);
console
.log(window
.location
.href
);
console
.log(window
.screen
.width
);
console
.log(window
.screen
.height
);
console
.log(window
.navigator
.userAgent
);
</script
>
<script type
="text/javascript">
alert();
window
.alert();
window
.prompt();
window
.document
;
</script
>
定时器的基本使用
<script type
="text/javascript">
var time
= setInterval(function(){
console
.log("我是定时器,么么哒");
},2000);
console
.log(time
);
clearInterval(time
);
console
.log("定时器后面的代码");
</script
>
运动套路
<script type
="text/javascript">
var div
= document
.querySelector("div");
var l
= 0;
var t
= 0;
setInterval(function(){
l
+=10;
t
+=5;
if(l
>= 300){
l
= 300;
}
t
= t
> 300 ? 300:t
;
div
.style
.left
= l
+ "px";
div
.style
.top
= t
+ "px";
},100);
</script
>
练习变脸
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
div{
position: absolute;
width: 187px;
height: 156px;
background: url(../img/6.jpg);
background-position: 0px -312px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<script type="text/javascript">
var div = document.querySelector("div");
step = 0;
l = 0;
isMove = false;
setInterval(function(){
if(isMove) return;
step++;
l += 10;
if(step > 2) step = 0;
div.style.backgroundPosition = -step*187+"px -312px";
div.style.left = l + "px";
},100);
document.onclick = function(){
isMove = !isMove;
}
</script>
转载请注明原文地址: https://lol.8miu.com/read-8855.html