可拖动面板

 

js

dragFunc: function (id) {
                var titile = $('#' + id);
                var parent = titile.parent();

                var isDown = false;

                var startx = 0;
                var starty;
                var startLeft;
                var startTop;

                titile.mousedown(function (e) {
                    isDown = true;
                    startx = e.clientX;
                    starty = e.clientY;
                    startLeft = parseInt(parent.offset().left);
                    startTop = parseInt(parent.offset().top);

                });

                $(document).mousemove(function (e) {
                    titile.css('cursor', 'move');
                    if (isDown) {
                        parent.offset({
                            left: e.clientX - (startx - startLeft),
                            top: e.clientY - (starty - startTop)
                        });
                    }
                });

                titile.mouseup(function () {
                    isDown = false;
                });
            }

  

* 绑定鼠标移动事件到 document上 

为什么:

这个我也写过拖动的  遇到和你一样的情况 
 确实是div不能绑定mousedown 或者mouse什么的事件  只能是整个页面绑定  ,许多网上的教程例子都没有绑定div层的。
绑定在div上 鼠标移出div层 事件就消失了,绑定document 也就是整个页面都有这个事件。

posted @ 2019-03-26 18:14  GordonDicaprio  阅读(330)  评论(0编辑  收藏  举报