---
title: "页面左侧隐藏弹出式菜单，跟随页面滚动！"
author: "ganglong99"
date: "2008-10-30T17:04:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2008-12-02T21:37:16Z"
id: 285208
url: "https://it-tech.iteye.com/blog/285208"
---

前段时间在网上找了很多关于菜单的例子，才发现菜单的样式太多了，觉得这种隐藏在页面左侧的弹出式菜单比较好看，仔细研究了一番，并且简化了一下，自己做了一个例子！

    将以下代码复制到文本文档，修改后缀为.html，然后双击即可看到效果（注：只能在IE浏览器中有效果，其他的浏览器没试过，firefox上不行）

> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
> &lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)"&gt;  
>  &lt;head&gt;  
>   &lt;title&gt; new document &lt;/title&gt;  
>   &lt;meta name="generator" content="editplus" /&gt;  
>   &lt;meta name="author" content="" /&gt;  
>   &lt;meta name="keywords" content="" /&gt;  
>   &lt;meta name="description" content="" /&gt;  
>  &lt;/head&gt;
> 
> &lt;style&gt;  
> #menu{  
> visibility:hidden;  
> cursor:hand;  
> position:absolute;  
> top:150px;  
> }  
> #menu table{  
> width:150px;  
> background-color:black;  
> border-style:none;  
> cursor:hand;  
> }  
> .bar{  
> background-color:#0099FF;  
> font-size:16px;  
> font-weight:bold;  
> text-align:center;  
> }  
> .menu{  
> text-align:center;  
> width:16px;  
> background-color:#FF6666;  
> font-size:13px;  
> }  
> .menuItem{  
> background-color:white;  
> height:20px;  
> font-size:12px;  
> text-align:center;  
> }  
> &lt;/style&gt;  
> &lt;script language="JavaScript"&gt;  
>  function move(x) {  
>   menu.style.pixelLeft += x;  
>   menu.style.visibility = "visible";  
>  }  
>  function positionmenu(){  
>   move(-132);  
>  }  
>  function makeStatic() {  
>   if (typeof window.pageYOffset != 'undefined') {  
>       diffY = window.pageYOffset;  
>   }  
>   else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {  
>       diffY = document.documentElement.scrollTop;  
>   }  
>   else if (typeof document.body != 'undefined') {  
>       diffY = document.body.scrollTop;  
>   }  
>   menu.style.pixelTop=diffY+150;  
>  }  
>  setInterval("makeStatic()",1);  
>  window.onload=positionmenu;  
> &lt;/script&gt;  
> &lt;body&gt;  
>  &lt;div id="menu" onmouseover="move(132)" onmouseout="move(-132)"&gt;  
>  &lt;table cellpadding="0" cellspacing="1"&gt;  
>   &lt;tr&gt;  
>    &lt;td class="bar"&gt;  
>     Menu  
>    &lt;/td&gt;  
>    &lt;td class="menu" rowspan="100"&gt;  
>     菜&lt;br&gt;&lt;br&gt;&lt;br&gt;单  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>   &lt;tr&gt;  
>    &lt;td class="menuItem"&gt;  
>     网络管理  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>   &lt;tr&gt;  
>    &lt;td class="menuItem"&gt;  
>     修改密码  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>   &lt;tr&gt;  
>    &lt;td class="menuItem"&gt;  
>     数据查询  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>   &lt;tr&gt;  
>    &lt;td class="menuItem"&gt;  
>     数据查询  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>   &lt;tr&gt;  
>    &lt;td class="menuItem"&gt;  
>     数据查询  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>   &lt;tr&gt;  
>    &lt;td class="menuItem"&gt;  
>     数据查询  
>    &lt;/td&gt;  
>   &lt;/tr&gt;  
>  &lt;/table&gt;  
>  &lt;/div&gt;  
>  &lt;div style="height:2000px;"&gt;  
>  &lt;/div&gt;  
> &lt;/body&gt;  
> &lt;/html&gt;