Wednesday, June 19, 2013

jQuery Right Click Context Menu Example | Custom jQuery Right Click Menu

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cri.aspx.cs" Inherits="cri" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Custom Right Click using jQuery</title>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

<script type="text/javascript">

$(document).ready(function () {

try {

$(document).bind("contextmenu", function (e) {



e.preventDefault();

$("#custom-menu").css({ top: e.pageY + "px", left: e.pageX + "px" }).show(100);



});

$(document).mouseup(function (e) {

var container = $("#custom-menu");

if (container.has(e.target).length == 0) {



container.hide();

}

});

}

catch (err) {



alert(err);

}

});

</script>

<style type="text/css">




#custom-menu





{

z-index: 1000;

position: absolute;

border: solid 2px black;

background-color: white;

padding: 5px 0;

display: none;



}

#custom-menu ol



{

padding: 0;

margin: 0;

list-style-type: none;

min-width: 130px;

width: auto;

max-width: 200px;

font-family:Verdana;

font-size:12px;



}

#custom-menu ol li



{

margin: 0;

display: block;

list-style: none;

padding: 5px 5px;



}

#custom-menu ol li:hover



{

background-color: #efefef;



}

#custom-menu ol li:active



{

color: White;

background-color: #000;



}

#custom-menu ol .list-devider



{

padding: 0px;

margin: 0px;



}

#custom-menu ol .list-devider hr



{

margin: 2px 0px;



}

#custom-menu ol li a



{

color: Black;

text-decoration: none;

display: block;

padding: 0px 5px;



}

#custom-menu ol li a:active



{

color: White;



}

</style>

</head>

<body>

<form id="form1" runat="server">

<div id="custom-menu">

<ol>

<li><a href="#">Reply</a> </li>

<li><a href="#">Reply All</a> </li>

<li class="list-devider">

<hr />

</li>

<li><a href="#">Mark as unread</a> </li>

<li><a href="#">Delete</a> </li>

<li><a href="#">Archive</a> </li>

<li class="list-devider">

<hr />

</li>

<li><a href="#">Junk</a> </li>

<li><a href="#">View</a> </li>

</ol>

</div>

</form>

</body>

</html>

No comments:

Post a Comment