模拟QQ的停靠时隐藏效果,隐藏树形菜单

目前只实现了停靠在left和top

//script脚本
//鼠标悬停
	function showTreeMenu() {
		//获取treeMenu的top和left的值	
		var posTop = document.getElementById("treeMenu").offsetTop+document.body.scrollTop;
		var posLeft = document.getElementById("treeMenu").offsetLeft;
		
		if(posLeft<=0){ //判断当前是否停靠在左侧
				//$("img[name=switch]").attr("src", "images/closeTree.jpg"); //设置图片
				$("#treeMenu").attr("style",
						"width:200px;height:250px;left:0px;top:"+posTop+"px;");
		} 
		
		if(posTop<=-10){ //判断当前是否停靠在屏幕上方
				//$("img[name=switch]").attr("src", "images/closeTree.jpg"); //设置图片
				$("#treeMenu").attr("style",
						"width:200px;height:250px;left:"+posLeft+"px;top:-10px;");
		} 
	}
	//鼠标移出
	function hideTreeMenu(){
		var posTop = document.getElementById("treeMenu").offsetTop+document.body.scrollTop;
		var posLeft = document.getElementById("treeMenu").offsetLeft;
		
		if(posLeft<=0){ //判断当前是否停靠
			//$("img[name=switch]").attr("src", "images/openTree.jpg");
			$("#treeMenu").attr("style",
					"width:200px;height:250px;left:-155px;top:"+posTop+"px;");
		}
		
		if(posTop<=-10){
			//$("img[name=switch]").attr("src", "images/openTree.jpg");
			$("#treeMenu").attr("style",
					"width:200px;height:250px;left:"+posLeft+"px;top:-210px;");
		}
	}
 	
 	$(function(){
 		$("#treeMenu").draggable({
 			//easyUI的div拖拽
 			//onStopDrag:拖拽停止时触发
	        onStopDrag: function (e) {
	        	var posTop = document.getElementById("treeMenu").offsetTop+document.body.scrollTop;
				var posLeft = document.getElementById("treeMenu").offsetLeft;
				if(posLeft<0){
					$("#treeMenu").attr("style",
					"width:200px;height:250px;left:-155px;top:"+posTop+"px;");
				}
				if(posTop<-10){
					$("#treeMenu").attr("style",
					"width:200px;height:250px;left:"+posLeft+"px;top:-210px;");
				}
	        }
    	    });
    });

//需要隐藏的树形菜单
//使用easyui和zTree
 <div id="treeMenu" class="easyui-draggable"
			style="width:200px;height:210px;left:-155px;top:100px;"
			onmouseover = "showTreeMenu()" onmouseout = "hideTreeMenu()">
			<ul id="positionzTree" class="ztree"
				style="width:150px;height:200px;float:left"></ul>
</div>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值