jQuery实现div拖拽效果实例分析

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <script type="text/javascript" src="https://www.jb51.net/jquery-1.7.2.min.js"></script> <style type="text/css"> /*模块拖拽*/ .drag{position:absolute;width:100px;height:100px;border:1px solid #ddd;background:#FBF2BD;text-align:center;padding:5px;top:100px;left:20px;cursor:move;} </style> <script type="text/javascript"> // 模块拖拽 $(function(){ var _move=false;//移动标记 var _x,_y;//鼠标离控件左上角的相对位置 $(".drag").click(function(){ //alert("click");//点击(松开后触发) }).mousedown(function(e){ _move=true; _x=e.pageX-parseInt($(".drag").css("left")); _y=e.pageY-parseInt($(".drag").css("top")); $(".drag").fadeTo(20, 0.5);//点击后开始拖动并透明显示 }); $(document).mousemove(function(e){ if(_move){ var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置 var y=e.pageY-_y; $(".drag").css({top:y,left:x});//控件新位置 } }).mouseup(function(){ _move=false; $(".drag").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明 }); }); </script> </head> <body> <!--模块拖拽--> <div>这个可以拖动哦 ^_^</div> </body> </html>

$("#question_pic").bind("click",function(event){ event.stopPropagation(); //防止冒泡事件响应 $("#chat_question").hide("slow"); });

$("#chatLineHolder").scrollTop(10000); //保持最下一行,不用滚

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery拖拽特效与技巧总结》、《jQuery常见经典特效汇总》、《jQuery扩展技巧总结》、《jquery选择器用法总结》及《jquery常用操作技巧汇总

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjxwzy.html