javascript - Issues about coordinate calculation after trasform
巴扎黑
巴扎黑 2017-07-01 09:12:23
0
1
1482

After I made a function of dragging pictures in the parent container, I used transform to change the parent container, rotate it, stretch it, etc. After that, the calculation of the coordinates started to get messy. I would like to ask if What should I do if I want him to work normally?
The dragging code is as follows:
$(function(){

 var dragging = false;
        var iX, iY;
        var qX, qY;
        var tempid;
         $(".dragcontain").mousedown(function(e) {
            dragging = true;
            iX = accSub(e.clientX,this.offsetLeft);
            iY = accSub(e.clientY,this.offsetTop);                
            qX = $(e.target).children().position().left;
            qY = $(e.target).children().position().top;
            console.log(qX,qY);
            console.log(iX,iY);
            this.setCapture && this.setCapture();
             return false;
        });
        document.onmousemove = function(e) {
            if (dragging) {
            var e = e || window.event;
            console.log("sX:",e.clientX,"sY:",e.clientY);
            var nX = accSub(e.clientX,e.target.offsetLeft);
            var nY = accSub(e.clientY,e.target.offsetTop);
            console.log(e.clientX,e.target.offsetLeft)
            var mX = accSub(nX,iX);
            var mY = accSub(nY,iY);
            var oX = accAdd(qX,mX);
            var oY = accAdd(qY,mY);
            $(e.target).children().css({"left":oX + "px", "top":oY + "px"});
            console.log("iX:",iX,"iY:",iY);
            console.log("oX:",oX,"oY:",oY);
            console.log("nX:",nX,"nY:",nY);
            console.log("mX:",mX,"mY:",mY);
            console.log("qX:",qX,"qY:",qY);
            console.log("");
            return false;
            }
        };
        $(document).mouseup(function(e) {
            dragging = false;
            e.cancelBubble = true;
            iX=0;
            iY=0;
        })    

})

Just after rotating the dragcontain to rotate (45deg), it started to get messy, and the coordinates went directly to more than -1000

巴扎黑
巴扎黑

reply all(1)
Ty80

Transform rotation and scaling all have base points, transform-origin

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template