JavaScript~~块移动事件

块移动事件

$div.find('.d-s-scroll').mousedown(function(e){
	var e = e || window.event;
	var h = e.clientY;
//				var w = e.clientX;
	//获得是鼠标按下时相对于元素的位置
//				var ex = w - wrap.offsetLeft;
	var ey = h - $div.find('.d-s-scroll')[0].offsetTop;
	$div.find('.d-s-scroll').mousemove(function(h){
		var h = h||window.event;
		var  h1 = h.clientY;
		var  w1 = h.clientX;
//					wrap.style.left=(w1-ex)+"px"; 
//					wrap.style.top=(h1-ey)+"px";
		if((h1-ey) > 0){
			if((h1-ey) > ($div.height()-19-19-152)){
				$(e.target).css({'top':($div.height()-19-19-152)+'px'});
			}else{
				$(e.target).css({'top':(h1-ey)+'px'});
			}
		}else{
			$(e.target).css({'top':'0px'});
		}
	});
});


猜你喜欢

转载自blog.51cto.com/dd118/2497368