当前位置: 代码迷 >> Web前端 >> jquery随便拖动div效果
  详细解决方案

jquery随便拖动div效果

热度:90   发布时间:2012-09-24 13:49:41.0
jquery随意拖动div效果
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<style>
.test{text-align:center;width:300px;height:30px;line-height:30px;background:#f60;position:absolute;}
.test:hover{cursor:move;}
</style>
<div class="test">测试</div>
<br/><br/>
<h1>如果无效请刷新下页面..</h1>
<script>
	;$(function(){
		var isMove=false;
		$(".test").mousedown(function(){isMove=true;}).mouseup(function(){isMove=false;});
		$(document).mousemove(function(e){
			if(!isMove){return;};
			var X=e.clientX-parseInt($(".test").width()/2);
			var Y=e.clientY-parseInt($(".test").height()/2);
			$(".test").css({"left":X,"top":Y,"cursor":"move"});
		});
	});
</script>


来自:http://www.zhjie.net/drag-the-div-jquery-random-effects.htm




 

  相关解决方案