asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
    $.fn.extend({
       drag: function(limit, sFunc, mFunc, eFunc){//limit range, start handler, moving handler, end handler
           return this.each(function(){
                var _this = this;
                if($.browser.msie) {
                    this.onselectstart = function(){return false};
                    if(this.style.background == "") this.style.background = "#fff";
                }
                if($.browser.mozilla) this.style.MozUserSelect = 'none';
                this.style.cursor = "move";
                $(this).mousedown(function(e){
                      sFunc && sFunc.call(this);                    
                      var offset = $(this).offset();                     
                      var screenX = e.screenX, screenY = e.screenY, w = this.offsetWidth, h = this.offsetHeight;
                      $(document).mousemove(function(e2){
                            if($.browser.msie && e.which != 1)   return ($(document).unbind(), eFunc.call(_this));
                            var curLeft = offset.left + e2.screenX - screenX, curTop = offset.top + e2.screenY - screenY;
                            if(!limit) limit = {minX: -20000, maxX: 20000, minY: -20000, maxY : 20000};
                            curLeft = curLeft < limit.minX ? limit.minX : ((curLeft + w) > limit.maxX ? (limit.maxX - w) : curLeft);
                            curTop = curTop < limit.minY ? limit.minY : ((curTop + h) > limit.maxY ? (limit.maxY - h) : curTop);
                           $(_this).css({position: "absolute", left: curLeft, top: curTop});
                           if($.browser.msie && _this.tagName == "IMG") e2.preventDefault();
                           mFunc && mFunc.call(_this);
                      });
                      $(document).mouseup(function(){
                         $(document).unbind();
                         eFunc && eFunc.call(_this);
                      });
                      if(this.tagName == "IMG") e.preventDefault();
                });               
           });
       }
    });
posted on 2008-11-01 22:13 汪杰 阅读(604) 评论(1)  编辑 收藏 引用 所属分类: jquery

FeedBack:
# re: jq之拖动(by asfman)
2008-11-02 23:57 | 汪杰
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<style type="text/css">
#openwin{width: 300px; font-size: 12px; border: 1px solid rgb(112, 156, 210);}
.hd{background: #709cd2; padding: 5px 2px; color: #fff; border: 1px solid #fff;}
h2{ margin: 0; padding: 0; font-size: 14px;}
.closewin{float: right; width: 18px; background: url(dialogclose.gif) left center; height: 17px;}
p{margin: 0; padding: 5px 6px; text-indent: 2em;}
</style>
<script type="text/javascript">
<!--
$.fn.extend({
drag: function(parent, limit, sFunc, mFunc, eFunc){//limit range, start handler, moving handler, end handler
return this.each(function(){
var _this = parent ? this.parentNode : this;
if($.browser.msie) {
this.onselectstart = function(){return false};
if($(_this).css("backgroundColor") == "transparent")_this.style.background = "#fff";
}
if($.browser.mozilla) this.style.MozUserSelect = 'none';
this.style.cursor = "move";
$(this).mousedown(function(e){
sFunc && sFunc.call(_this);
var offset = $(_this).offset();
var screenX = e.screenX, screenY = e.screenY, w = _this.offsetWidth, h = _this.offsetHeight;
$(document).mousemove(function(e2){
if($.browser.msie && e.which != 1) return ($(document).unbind(), eFunc.call(_this));
var curLeft = offset.left + e2.screenX - screenX, curTop = offset.top + e2.screenY - screenY;
if(!limit) limit = {minX: -20000, maxX: 20000, minY: -20000, maxY : 20000};
curLeft = curLeft < limit.minX ? limit.minX : ((curLeft + w) > limit.maxX ? (limit.maxX - w) : curLeft);
curTop = curTop < limit.minY ? limit.minY : ((curTop + h) > limit.maxY ? (limit.maxY - h) : curTop);
$(_this).css({position: "absolute", left: curLeft, top: curTop});
if($.browser.msie && _this.tagName == "IMG") e2.preventDefault();
mFunc && mFunc.call(_this);
});
$(document).mouseup(function(){
$(document).unbind();
eFunc && eFunc.call(_this);
});
if(this.tagName == "IMG") e.preventDefault();
});
});
}
});
$(function(){
$(".hd").drag(true);
});
//-->
</script>
</head>
<body>

<div id="openwin">
<div class="hd">
<div class="closewin"></div>
<h2>窗口名字</h2>
</div>
<div id="bd">
<p>福建炼厂PP装置现产拉丝T30S,今日挂牌价普降1500元/吨。最新拉丝T30S挂牌价7500元/吨,膜料T36F挂牌价7500元/吨。厂家销售正常。</p>
</div>
</div>
<img align="absmiddle" src="dialogclose.gif" />
</body>
</html>  回复  更多评论
  
只有注册用户登录后才能发表评论。

<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 456687
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜