-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path52(js运动效果原理-点击让图片显隐 ).html
55 lines (43 loc) · 1.31 KB
/
52(js运动效果原理-点击让图片显隐 ).html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#love{
display: inline;
}
</style>
<script type="text/javascript">
window.onload = function(){
//抓取元素
var love=document.getElementById("love") ;
var btn = document.getElementById("btn");
// var btn2 = document.getElementById("btn2");
// btn.onclick = function(){
// love.style.display = "none"
// }
// btn2.onclick = function(){
// love.style.display = "block"
// }
//方法:变量对应状态
var zhuangtai = "block" //状态为block,图片隐藏;时,
btn.onclick = function(){
if(zhuangtai == "block"){//状态为block,
love.style.display = "none";//图片隐藏
zhuangtai = "none";//此刻状态为none隐藏
}else if(zhuangtai == "none"){//再点击时,状态为none
love.style.display = "block"//图片显示
zhuangtai = "block";//此刻状态为block显示
}
}
}
</script>
</head>
<body>
<input type="button" id="btn" value="点击隐藏,再点击显示" />
<!--<input type="button" id="btn2" value="点击出现" />-->
<br /><br />
<img src="img/004.jpeg" id="love" style="border: 1px solid black;" />
</body>
</html>