// Plugin: jQuery.dragmove // Source: github.com/nathco/jQuery.dragmove // Author: Nathan Rutzky // Update: 1.0 (function($) { $.fn.dragmove = function(divParent) { return this.each(function() { var $document = $(document), $this = $(this), active, startX, startY; $this.on('mousedown touchstart', function(e) { active = true; startX = e.originalEvent.pageX - $this.offset().left; startY = e.originalEvent.pageY - $this.offset().top; if ('mousedown' == e.type) if(divParent){ click = divParent; }else { click = $this; } if ('touchstart' == e.type) if(divParent){ click = divParent; }else { touch = $this; } if (window.mozInnerScreenX == null) return false; }); $document.on('mousemove touchmove', function(e) { var topZhi = e.originalEvent.pageY - startY; var screenHeight = document.body.clientHeight || document.documentElement.clientHeight; if((e.originalEvent.pageY - startY)<0){ topZhi = 0; } if(e.originalEvent.pageY>screenHeight){ topZhi = screenHeight-48; //弹窗高度不固定,保留弹窗头部高度 } if ('mousemove' == e.type && active) click.offset({ left: e.originalEvent.pageX - startX, top: topZhi }); if ('touchmove' == e.type && active) touch.offset({ left: e.originalEvent.pageX - startX, top: e.originalEvent.pageY - startY }); }).on('mouseup touchend', function() { active = false; }); }); }; })(jQuery);