2012-12-11 148 views
3

我有以下菜單,在桌面上完美的作品。懸停在項目上時,出現二級菜單。隱藏懸停在點擊離開觸摸屏平板電腦/移動設備

在平板電腦/移動設備,這是一個點擊/觸摸

我想要的菜單懸停效果(對平板電腦的觸摸)的平板電腦/移動設備上點擊離開時消失。

例如ipad,當點擊我的清單,二級菜單顯示,但需要它消失時,點擊離開菜單

這可能嗎?

CSS:

* {outline:none; border:none; margin:0; padding:0; font:14px arial,sans-serif;} 
body {background: url(images/bg.gif) repeat;} 
#top {background: url(images/top_tile.png) repeat-x; height:140px; width:100%;} 
.wrap {width:980px; margin:0 auto;} 
#top1 {height:60px;} 
.logo {padding-top:10px;} 
#menu {height:48px;} 
/*NAV*/ 
#nav{ 
    list-style:none; 
    font-weight:bold; 
    /* Clear floats */ 
    float:left; 
    width:100%; 
} 
#nav li{ 
    float:left; 
    margin-right:10px; 
    position:relative; 
} 
#nav a{ 
    display:block; 
    padding:20px 25px 7px 15px; 
    color:#333; 
    height:25px; 
    text-decoration:none; 
} 
#nav a:hover{ 
    color:#fff; 
    background:#ff9900; 
    text-decoration:none; 
} 

/*--- DROPDOWN ---*/ 
#nav ul{ 
    background:#fff; 
    list-style:none; 
    position:absolute; 
    left:-9999px; 
    min-width:200px; 
    border-radius:0px 0px 3px 3px; 
    border:1px solid #ccc; 
} 
#nav ul li{ 
    padding-top:1px; 
    float:none; 
    background:#fff; 
    } 
#nav ul a{ 
    white-space:nowrap; 
    font-size:13px; 
    color:#666; 
    padding: 10px 0px 5px 15px; 
} 
#nav li:hover ul{ 
    left:0; 

} 
#nav li:hover a{ 
    background:#ff9900; 
    text-decoration:none; 
} 
#nav li:hover ul a{ 
    text-decoration:none; 
    background:#fff; 

} 
#nav li:hover ul li a:hover{ 
    background:#ff9900; 
    color:#fff; 
} 

HTML:

<body> 
    <div id="top"> 
     <div id="top1" class="wrap"><img src="images/logo.gif" class="logo" /></div> 
      <div id="menu" class="wrap"> 
       <ul id="nav"> 
        <li><a href="#">My Lists</a> 
         <ul> 
          <li><a href="#">List 1</a></li> 
          <li><a href="#">List 2</a></li> 
          <li><a href="#">List 3</a></li> 
          <li><a href="#">View all Lists</a></li> 
         </ul> 
        </li> 
        <li><a href="/pages/following">Following</a> 
         <ul> 
          <li><a href="#">Follow 1</a></li> 
          <li><a href="#">Follow 2</a></li> 
          <li><a href="#">Follow 3</a></li> 
          <li><a href="#">View all Follows</a></li> 
         </ul> 
        </li> 
       </ul> 
      </div> 
     </div> 
    </div> 
</body> 

Fiddle

回答

1
$(document).click(function() { 
alert("me"); 
}); 

$(".myDiv").click(function(e) { 
e.stopPropagation(); // This is the preferred method. 
return false;  // This should not be used unless you do not want 
        // any click events registering inside the div 
}); 

---如此地。 jQuery hide element when clicked anywhere on the page

相關問題