我是靠谱客的博主 优秀汉堡,这篇文章主要介绍js实现自动隐藏侧边栏,现在分享给大家,希望可以做个参考。

复制代码
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta content="text/html charset=utf-8" http-equiv="Content-Type"> <title>Title</title> <script> function demo1(){ var content=document.getElementById("content"); var tag=document.getElementById("tag"); var ispeed=5; timer=null; time2=null; tag.onmouseover=content.onmouseover=function (ev) { clearInterval(timer); clearInterval(time2); timer=setInterval(function(){ if(content.offsetLeft>=0){ clearInterval(timer); }else{ content.style.left=content.offsetLeft+ispeed+"px"; tag.style.left=tag.offsetLeft+ispeed+"px"; } },30); } tag.onmouseout=content.onmouseout=function (ev) { clearInterval(time2); clearInterval(timer); time2=setInterval(function(){ document.title=content.offsetLeft+""; if(tag.offsetLeft<=0){ clearInterval(time2); }else{ content.style.left=content.offsetLeft-ispeed+"px"; tag.style.left=tag.offsetLeft-ispeed+"px"; } },30); } } </script> <style> #content{width:100px;height:200px;background-color: #cccccc;position:absolute;top:20px;left:-100px;} #tag{width:30px;height:80px;background-color: #FFCC00;text-align: center;position:absolute;left:0px;top:50px;} </style> </head> <body> <div id="content"></div> <div id="tag">分享到</div> <script> demo1(); </script> </body> </html>

使用js代码实现的,很少会写js程序,尝试写了一个,处理个半天,

最后

以上就是优秀汉堡最近收集整理的关于js实现自动隐藏侧边栏的全部内容,更多相关js实现自动隐藏侧边栏内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部