簡單又漂亮的右鍵選單 jquery-simple-context-menu
實際執行畫面 |
使用方法:
第一步 先載入程式所需要的檔案
//使用Google ajax API 直接連結 jQuery 1.8.2的min版本
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
//jquery-simple-context-menu 的主程式碼
<script src="jquery.contextmenu.js"></script>
第二步 加入選單的 CSS 樣式設計
.contextMenuPlugin {
-webkit-user-select: none;
display: none;
font-family: tahoma, arial, sans-serif;
font-size: 11px;
position: absolute;
left: 100px;
top: 100px;
min-width: 100px;
list-style-type: none;
margin: 0;
padding: 0;
background-color: #f7f3f7;
border: 2px solid #f7f7f7;
outline: 1px solid #949694;
}
.contextMenuPlugin > li {
margin: 0 0 0 0;
padding: 1px;
background-repeat: no-repeat;
}
.contextMenuPlugin > li > a {
position: relative;
display: block;
padding: 3px 3px 3px 28px;
color: ButtonText;
text-decoration: none;
margin: 1px;
}
.contextMenuPlugin > li > a img {
position: absolute;
left: 3px;
margin-top: -2px;
width: 16px;
height: 16px;
}
.contextMenuPlugin > li > a:hover {
border: 1px solid #fffbff;
outline: 1px solid #b5d3ff;
margin: 0;
background: -moz-linear-gradient(top, rgba(239,239,255,0.5) 0%, rgba(223,223,255,0.5) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(239,239,255,0.5)), color-stop(100%,rgba(223,223,255,0.5))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(239,239,255,0.5) 0%,rgba(223,223,255,0.5) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(239,239,255,0.5) 0%,rgba(223,223,255,0.5) 100%); /* Opera11.10+ */
background: -ms-linear-gradient(top, rgba(239,239,255,0.5) 0%,rgba(223,223,255,0.5) 100%); /* IE10+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#80efefff', endColorstr='#80dfdfff',GradientType=0 ); /* IE6-9 */
background: linear-gradient(top, rgba(239,239,255,0.5) 0%,rgba(223,223,255,0.5) 100%); /* W3C */
cursor: default;
}
.contextMenuPlugin > li.divider {
border-top: 1px solid #e7e3e7;
border-bottom: 1px solid #ffffff;
height: 0;
padding: 0;
margin: 5px 0 5px 27px;
}
.contextMenuPlugin > .header {
background: rgb(90,90,90); /* Old browsers */
background: -moz-linear-gradient(top, rgba(90,90,90,1) 0%, rgba(20,20,20,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(90,90,90,1)), color-stop(100%,rgba(20,20,20,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(90,90,90,1) 0%,rgba(20,20,20,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(90,90,90,1) 0%,rgba(20,20,20,1) 100%); /* Opera11.10+ */
background: -ms-linear-gradient(top, rgba(90,90,90,1) 0%,rgba(20,20,20,1) 100%); /* IE10+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5a5a5a', endColorstr='#141414',GradientType=0 ); /* IE6-9 */
background: linear-gradient(top, rgba(90,90,90,1) 0%,rgba(20,20,20,1) 100%); /* W3C */
position: relative;
cursor: default;
padding: 3px 3px 3px 3px;
color: #ffffff;
}
.contextMenuPlugin > .gutterLine {
position: absolute;
border-left: 1px solid #e7e3e7;
border-right: 1px solid #ffffff;
width: 0;
top: 0;
bottom: 0;
left: 26px;
z-index: 0;
}
第三步 在HTML需要用到右鍵選單的部分加上識別
<div id="MyID">hello</div>
第四步 加入 JavaScript 的程式
$(function(){
$('#mythingy').contextPopup({
title: '標題',
items: [
{label:'單文字',
icon:'選單圖片',
action:function() {
/*按下後執行*/ }
},
{label:'單文字',
icon:'選單圖片',
action:function() {
/*按下後執行*/ }
},null, /*分隔 */
{label:'單文字',
icon:'選單圖片',
action:function() {
/*按下後執行*/ }
},
{label:'單文字',
icon:'選單圖片',
action:function() {
/*按下後執行*/ }
},
]});
});
作者網站:http://joewalnes.github.com/jquery-simple-context-menu/
檔案大小:24.1 KB(包含範例)
檔案下載:http://github.com/joewalnes/jquery-simple-context-menu/zipball/master
檔案備份:下載
0 意見