js实现自动隐藏侧边栏


<html>
<head>
    <meta content="text/html charset=utf-8" http-equiv="Content-Type">
    <title>Titletitle>
    <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程序,尝试写了一个,处理个半天,

你可能感兴趣的:(html+css)