jQuery實(shí)現(xiàn)右鍵菜單、遮罩等效果代碼
最近要做個(gè)某管理系統(tǒng)的界面,然后涉及到右鍵菜單,因?yàn)橹皼](méi)有做過(guò)所以就做了一下~感覺(jué)還可以,不過(guò)我個(gè)人不是很喜歡右鍵菜單的這種形式。
操作:在固定區(qū)域內(nèi)點(diǎn)擊鼠標(biāo)右鍵出現(xiàn)菜單,然后選擇任意一項(xiàng)后進(jìn)行對(duì)應(yīng)頁(yè)面的跳轉(zhuǎn)。剛開(kāi)始的想法是用catch..case..的方法,對(duì)應(yīng)不同的選項(xiàng),只改變彈出層里的內(nèi)容,但是內(nèi)容都要用jQuery生成拼接,所以選用了比較簡(jiǎn)單的頁(yè)面跳轉(zhuǎn)。
下面就只貼上一個(gè)示例頁(yè)面的相關(guān)代碼。
先上效果圖:

**index.html主要代碼**
<div id="myMenu" > <ul> <li>管理應(yīng)用</li> <li>添加應(yīng)用</li> <li>維護(hù)應(yīng)用賬號(hào)</li> <li>修改密碼</li> <li>示例界面</li> </ul> </div> <div id="mask"> </div> <div id="textbox"> 主界面 </div>
**page_test.html主要代碼**
<div id="textbox">
主界面
</div>
<div id="maskbox">
<div id='admin' class='module1'>
<div class='top'>
管理應(yīng)用
<img class="img_close" src="../images/close.png" alt="">
</div>
<div class='mid'>
<div class='mid_left'>
<div class='title'>應(yīng)用分類:總部</div>
<ul class='icon_list'>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
<li><img src='../images/45x45/qq.jpg' alt=''> <span>QQ</span></li>
</ul>
</div>
<div class='mid_right'>
<div class='title'>添加應(yīng)用</div>
<div class="content">
<form action="">
<table>
<tr>
<td>應(yīng)用機(jī)構(gòu):</td>
<td>
<select class="text1" name="">
<option value=""></option>
</select>
</td>
</tr>
<tr>
<td>應(yīng)用類型:</td>
<td>
<select class="text1" name="">
<option value=""></option>
</select>
</td>
</tr>
<tr>
<td>應(yīng)用名稱:</td>
<td>
<input type="text" class="text2">
</td>
</tr>
<tr>
<td>應(yīng)用代碼:</td>
<td>
<input type="text" class="text2">
<span class="point">(字母、數(shù)字及組合;唯一)</span>
</td>
</tr>
<tr>
<td>接入類型:</td>
<td>
<select class="text1" name="">
<option value=""></option>
</select>
</td>
</tr>
<tr>
<td>超時(shí)時(shí)間:</td>
<td>
<select class="text1" name="">
<option value=""></option>
</select>
</td>
</tr>
<tr>
<td>選擇圖標(biāo):</td>
<td>
<input type="text" class="text2">
<span>選擇</span>
</td>
</tr>
<tr>
<td>應(yīng)用地址:</td>
<td>
<input type="text" class="text2">
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" class="del button" value="刪除">
<input type="button" class="reset button" value="重置">
<input type="button" class="save button" value="保存">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div class='end'></div>
</div>
</div>
**reset.css代碼(引入主頁(yè))**
*{
padding: 0;
margin: 0;
font-family: '微軟雅黑'
}
#mask{
position: absolute;
left: 0;
top: 0;
z-index: 9000;
display: block;
}
#myMenu{
position: absolute;
display: none;
z-index: 9999;
background: white;
border: 1px solid;
width: 130px;
height: 130px;
}
ul li{
list-style: none;
height: 25px;
line-height:25px;
font-size: 14px;
cursor: pointer;
margin-left: 5px;
border-bottom: 1px solid black;
}
ul li:nth-child(5){
border-bottom:none;
}
#textbox{
background: orange;
width: 380px;
border: 2px solid;
}
a{
text-decoration: none;
color: black;
}
a:hover{
color: white;
background: black;
}
**main.css代碼(引入主頁(yè)和跳轉(zhuǎn)頁(yè))**
*{
font-size: 16px;
color:black;
padding: 0;
margin: 0;
font-family: 微軟雅黑;
}
/*.top{
background: url("../images/close.png")760px center no-repeat;
}*/
.top img{
float: right;
margin-top: 13px;
margin-right: 20px;
}
/*遮罩樣式*/
#maskbox{
position:absolute;
left:0;
top:0;
height: 100%;
width: 100%;
background:rgba(0,0,0,0.6);
}
#maskbox .module1{
width: 800px;
height: 500px;
border-radius: 15px;
border: 1px solid #BFDCE3;
margin: 0 auto;
margin-top: 40px;
}
#maskbox .top{
border-radius: 15px 15px 0 0;
height: 46px;
line-height: 46px;
width: 800px;
background-color: #F1F7F2;
border: 1px solid #BFDCE3;
text-indent: 20px;
}
#maskbox .mid{
height: 418px;
width: 800px;
background-color: white;
border: 1px solid #BFDCE3;
}
#maskbox .end{
height: 36px;
width: 800px;
background-color: #F1F7F2;
border-radius: 0 0 15px 15px ;
border: 1px solid #BFDCE3;
}
.mid_left,.mid_right{
display: inline-block;
height: 418px;
}
.mid_left{
width: 270px;
float: left;
border-right: 1px solid #BFDCE3;
}
.mid_right{
width: 528px;
border-right: 1px solid #BFDCE3;
}
.title{
position: relative;
height: 40px;
line-height: 40px;
text-align: center;
color:#DD9A6A;
border-bottom: 1px solid #BFDCE3;
}
.mid_right .title{
text-align: left;
text-indent: 20px;
}
ul.icon_list{
height: 377px;
width: 270px;
overflow: auto;
}
ul.icon_list li{
border-bottom: 1px solid #BFDCE3;
height: 72px;
list-style: none;
line-height: 72px;
padding-left: 20px;
}
ul.icon_list li img{
vertical-align: middle;
margin-right: 20px;
}
.text1{
width: 195px;
height: 28px;
}
.text2{
width: 192px;
height: 28px;
}
.button{
width: 80px;
height: 28px;
border-radius: 5px;
background-color: white;
border:1px solid #a8a8a8;
font-size: 13px;
}
.point{
font-size: 14px;
color:red;
}
**test.css代碼**
/*mid_right*/
table{
margin-left: 15px;
}
table tr td{
height: 35px;
}
table tr td:nth-child(1){
height: 35px;
width: 100px;
}
table tr td:nth-child(2){
height: 35px;
width: 390px;
}
table tr:nth-child(9) td{
height: 100px;
padding: 0 50px;
}
table tr:nth-child(9) .button{
margin-right: 60px;
}
table tr:nth-child(9) .button:nth-child(3){
margin-right: 0;
}
table span{
font-size: 14px;
color:deepskyblue;
}
table span.point{
font-size: 14px;
color:red;
}
**func.js代碼(引入主頁(yè))**
//鼠標(biāo)右擊菜單
$(window).ready(function() {
$('#myMenu').hide();
$('#textbox').bind("contextmenu",function(e){
//顯示菜單
$('#myMenu').show(500);
//跟隨鼠標(biāo)位置
$('#myMenu').css({
'top':e.pageY+'px',
'left':e.pageX+'px'
});
//屏蔽默認(rèn)右鍵菜單
return false;
});
});
**main.js代碼(引入主頁(yè))**
//獲得選擇的操作名
var check;
var checkmenu;
var choose = function(){
$("#myMenu ul>li").bind('click',function(){
check = $(this).text();
page(check);
});
};
choose();
var page = function(check){
/*
//統(tǒng)一樣式改變
//右鍵列表隱藏
$("#myMenu").hide();
//出現(xiàn)遮罩
$("#textbox").after("<div id='maskbox'></div>");
checkmenu = 1;
windowwidth = $(window).width();
windowheight = $(window).height();
$("#maskbox").css({
'height': windowheight,
'width': windowwidth
});
*/
switch (check){
case "管理應(yīng)用":
page_admin();
break;
case "添加應(yīng)用":
page_add();
break;
case "維護(hù)應(yīng)用賬號(hào)":
page_maintain();
break;
case "修改密碼":
page_modify();
break;
case "示例界面":
page_test();
break;
}
};
var page_admin = function(){
console.log("管理應(yīng)用");
window.location.href="page/page_admin.html";
};
var page_add = function(){
console.log("添加應(yīng)用");
window.location.href="page/page_add.html";
};
var page_maintain = function(){
console.log("維護(hù)應(yīng)用賬號(hào)");
window.location.href="page/page_maintain.html";
};
var page_modify = function(){
console.log("修改密碼");
window.location.href="page/page_modify.html";
};
var page_test = function(){
console.log("示例界面");
window.location.href="page/page_test.html";
};
//改變屏幕大小時(shí)
$(window).resize(function(){
if(checkmenu == 1) {
windowwidth = $(window).width();
windowheight = $(window).height();
$("#maskbox").css({
'height': windowheight,
'width': windowwidth
});
}
});
**com.js代碼**
//統(tǒng)一樣式改變
//右鍵列表隱藏
$("#myMenu").hide();
//出現(xiàn)遮罩
$("#textbox").after("<div id='maskbox'></div>");
checkmenu = 1;
windowwidth = $(window).width();
windowheight = $(window).height();
$("#maskbox").css({
'height': windowheight,
'width': windowwidth
});
//關(guān)閉彈窗 回到主界面
$(".img_close").bind("click",function(){
window.location.href="../index.html";
});
//點(diǎn)擊按鈕后也回到主界面
$(".save").click(function(){
window.location.href="../index.html";
});
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery實(shí)現(xiàn)彈出帶遮罩層的居中浮動(dòng)窗口效果
- jQuery彈出遮罩層效果完整示例
- jQuery操作dom實(shí)現(xiàn)彈出頁(yè)面遮罩層(web端和移動(dòng)端阻止遮罩層的滑動(dòng))
- Jquery實(shí)現(xiàn)遮罩層的簡(jiǎn)單實(shí)例(就是彈出DIV周圍都灰色不能操作)
- jQuery實(shí)現(xiàn)按鈕點(diǎn)擊遮罩加載及處理完后恢復(fù)的效果
- 使用jQuery制作遮罩層彈出效果的極簡(jiǎn)實(shí)例分享
- jquery實(shí)現(xiàn)簡(jiǎn)單的遮罩層
- Jquery實(shí)現(xiàn)自定義彈窗示例
- jquery制作彈窗提示窗口代碼分享
- jQuery實(shí)現(xiàn)簡(jiǎn)單彈窗遮罩效果
相關(guān)文章
Jquery實(shí)現(xiàn)textarea根據(jù)文本內(nèi)容自適應(yīng)高度
本文給大家分享的是Jquery實(shí)現(xiàn)textarea根據(jù)文本內(nèi)容自適應(yīng)高度,這些在平時(shí)的項(xiàng)目中挺實(shí)用的,所以抽空封裝了一個(gè)文本框根據(jù)輸入內(nèi)容自適應(yīng)高度的插件,這里推薦給小伙伴們。2015-04-04
jQuery實(shí)現(xiàn)Flash效果上下翻動(dòng)的中英文導(dǎo)航菜單代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)Flash效果上下翻動(dòng)的中英文導(dǎo)航菜單代碼,實(shí)例分析了jQuery基于鼠標(biāo)hover事件控制頁(yè)面元素動(dòng)畫(huà)效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
jquery load事件(callback/data)使用方法及注意事項(xiàng)
jquery load 事件使用方法,在網(wǎng)上有很多的相關(guān)介紹文章,不過(guò)大同小異,本文老生長(zhǎng)談,也介紹一下load事件使用方法,感興趣的朋友可以了解下,或許對(duì)你學(xué)習(xí)jquery有所幫助2013-02-02
jQuery倒計(jì)時(shí)代碼(超簡(jiǎn)單)
本文給大家分享一段超簡(jiǎn)單的代碼基于jquery實(shí)現(xiàn)倒計(jì)時(shí)功能,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下2017-02-02
layui選項(xiàng)卡效果實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了layui彈出層效果的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
jQuery表單獲取和失去焦點(diǎn)輸入框提示效果的實(shí)例代碼
這篇文章介紹了jQuery表單獲取和失去焦點(diǎn)輸入框提示效果的實(shí)例代碼,有需要的朋友可以參考一下2013-08-08
jQuery處理json數(shù)據(jù)返回?cái)?shù)組和輸出的方法
這篇文章主要介紹了jQuery處理json數(shù)據(jù)返回?cái)?shù)組和輸出的方法,涉及jQuery操作數(shù)組及json的技巧,需要的朋友可以參考下2015-03-03
jQuery實(shí)現(xiàn)圖片漸入漸出切換展示效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)圖片漸入漸出切換展示效果,需要的朋友可以參考下2015-08-08

