Stop canvas object outside the Canvas

canvas.on('object:scaling', function (event) {  // THIS EVENT WILL STOP RESIZE OVER THE CANVAS SIZE
                var el = event.target;

                widthPercentage = ((el.width * el.scaleX) / canvas.width) * 100;
                document.getElementById('textSizeSlider').value = widthPercentage;
                canvas.renderAll();              

                if (el && (el.height * el.scaleY) > 10 && (el.left + (el.width * el.scaleX)) < canvas.width && (el.top + (el.height * el.scaleY)) < canvas.height) {
                    previous_scaleY = el.scaleY;
                    previous_scaleX = el.scaleX;
                    previous_left = el.left;
                    previous_top = el.top;
                }

                if (el && (el.height * el.scaleX) < 10) {
                    el.left = previous_left;
                    el.top = previous_top;
                    el.scaleX = previous_scaleX;
                    el.scaleY = previous_scaleY;
                    el.lockScalingX = true;
                    el.lockScalingY = true;
                    canvas.renderAll();
                }

                if (el && (el.left + (el.width * el.scaleX) + 15) > canvas.width || (el.top + (el.height * el.scaleY)) > canvas.height) {
                    el.left = previous_left;
                    el.top = previous_top;
                    el.scaleX = previous_scaleX * 0.99;
                    el.scaleY = previous_scaleY * 0.99;
                    canvas.renderAll();
                }

            });
Post a Comment

Popular posts from this blog

[Solved] Hive installation error: java.net.URISyntaxException: Relative path in absolute URI

Install Android SDK in centOs

Installing arules package (Association Rules) in R