针对Ztree的右键弹出菜单(jquery.popupSmallMenu.js)

例子效果:

[img]http://dl2.iteye.com/upload/attachment/0100/1733/f1f93106-d46d-3aaa-825d-f7ab4570724e.png[/img]


右键菜单方便好用的有很多,长用的为jquery contextMenu.
官网: http://www.trendskitchens.co.nz/jquery/contextmenu/
用法: $("table td").contextMenu("myMenu")
问题: 可以看出右键菜单需要制定一个绑定的对象(table td), 但zTree要绑定事件,还需要获得每个节点的li,不是很好,它本身提供右键事件和右键菜单(不是很好看), 所以我们可以在右键事件位置下手, 自己仿照jquery ContextMenu.js 写一个插件([b]jquery.popupSmallMenu.js[/b]):

在ztree触发右键事件时,弹出菜单:

1.使用:
ztree 右键事件:
callback: {
onRightClick:OnRightClick
}

function OnRightClick(event, treeId, treeNode) {
ztree.selectNode(treeNode);
if(treeNode) {
//弹出菜单
$("#menu").popupSmallMenu({
event : event,
onClickItem : function(item) {
chuli(treeNode,item);
}
});

}
}

Html:

<ul id="menu" class="small-menu">
<li class="edit"><a href="#">编辑</a></li>
<li class="cut"><a href="#">添加</a></li>
<li class="copy"><a href="#">删除</a></li>

<li class="small-menu-separator"></li>
<li class="delete"><a href="#"><span class="icon icon-edit"></span>Zoom Out</a></li>
</ul>

CSS 样式 仿照jquery ContextMenu:

.small-menu {
position: absolute;
width: 120px;
z-index: 99999;
border: solid 1px #CCC;
background: #EEE;
padding: 0px;
margin: 0px;
display: none;
}

.small-menu li {
list-style: none;
padding: 0px;
margin: 0px;
}
.small-menu li A {
color: #333;
text-decoration: none;
display: block;
line-height: 20px;
height: 20px;
background-position: 6px center;
background-repeat: no-repeat;
outline: none;
padding: 1px 5px;
padding-left: 28px;
}

.small-menu li a:hover {
color: #FFF;
background-color: #3399FF;
}

.small-menu-separator {
padding-bottom:0;
border-bottom: 1px solid #DDD;
}

.small-menu LI.edit A { background-image: url(images/page_white_edit.png); }
.small-menu LI.cut A { background-image: url(images/cut.png); }
.small-menu LI.copy A { background-image: url(images/page_white_copy.png); }
.small-menu LI.paste A { background-image: url(images/page_white_paste.png); }
.small-menu LI.delete A { background-image: url(images/page_white_delete.png); }
.small-menu LI.quit A { background-image: url(images/door.png); }



/**
* @description
* small popup menu.
* @deprecated
* JQuery.js
* @author Malt
* @version 1.0
* Date: 2013-05-22
*/
(function($,undefined){
$.fn.popupSmallMenu = function(options) {
var $currMenu = $(this),
defaultOptions = {
event : null,
onClickItem : null
},
options = $.extend(defaultOptions,options);

var _smallMenu = {
popupSmallMenu : function() {
this._bindItemClick();
this._bindMenuEvent();
this._showMenu();
return $currMenu;
},
_bindMenuEvent : function() {
var thiz = this;
$currMenu.hover(function(){
},function(){
thiz._unBindItemClick();
$currMenu.hide();
});

$currMenu.click(function(){
thiz._unBindItemClick();
$currMenu.hide();
});
},
_showMenu : function() {
if(!options.event) {
alert('请传入鼠标事件');
}
$currMenu.css({
top:options.event.clientY+"px",
left:options.event.clientX+"px",
display:"block"
});
},
_bindItemClick : function() {
$currMenu.find('li').each(function(index,obj){
var $li = $(obj);
var itemIden = $li.attr('class');
$li.bind('click',function(event){
event.stopPropagation();
if(options.onClickItem
&& typeof options.onClickItem === 'function') {
options.onClickItem(itemIden);
}
});
});
}
,
_unBindItemClick : function(){
$currMenu.find('li').each(function(index,obj){
$(obj).unbind();
});
}
};

return _smallMenu.popupSmallMenu();
}
})(jQuery);


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值