[英]How to maintain fixed corner while resize a DIV element after rotate
Working in HTML div to rotate and resize with Javascript . 在HTML div中使用Javascript进行旋转和调整大小 。
I can't able to make a corner remains fixed while resize after rotate. 旋转后调整大小时,我无法使拐角保持固定 。
Possible duplicates are: 可能的重复项是:
How to calculate translate x and y value when resize after rotate..? 旋转后调整大小时如何计算x和y转换值?
Resize logic to maintain a fixed corner after rotate in javascript 在javascript中旋转后调整逻辑大小以保持固定的角
How to resize with fixed corner after rotate? 旋转后如何用固定的角调整大小?
No use for me from the above link. 从上面的链接对我没有用。
I need a similar functionality like this one, but its svg. 我需要一个像类似的功能这一个,但它的SVG。 I need this with div elements , not for svg.
我需要div元素 ,而不是svg。
I checked too more links like this one, those are only used to find corner positions after rotate, but after finding this how to set corner fixed while resize..? 我查过更像链接这一个,那些只是用来寻找旋转后的角落位置,但找到这个如何设置角落固定的,而调整后的..?
What is the step by step procedure to maintain opposite corners fixed when resize after rotate..? 旋转后调整大小时,如何保持对角固定不变的逐步步骤?
I used one sample code for reference to understand by need, but i achieved center based resize after rotate, i can't add all the codes. 我使用了一个示例代码作为参考,以根据需要进行理解,但是旋转后我实现了基于中心的调整大小,因此无法添加所有代码。 I can resize with corner fixed with
0 deg
and 360 deg
, but i need fixed corner with all others angles. 我可以使用固定为
0 deg
和360 deg
角来调整大小,但是我需要固定所有其他角度的角。
Note: To maintain fixed corner after rotate Canva and Powtoon made some adjustments in translate(x,y)
=> by Canva and left
, top
=> by Powtoon. 注:为了保持固定的角落旋转后Canva和Powtoon做出一些调整
translate(x,y)
由Canva =>和left
, top
=>由Powtoon。
Could it be a start? 可能是一个开始吗? (not the 100% solution, but a way to approach it, improvable):
(不是100%的解决方案,而是一种解决方案,可改进):
$(document).ready(function(){ /** * The rotation method * * @param domElement The element to rotate * @param origin The origin of the rotate * @param degree The degrees amount for the angle */ function rotate(domElement, origin, degree) { $(domElement) .css({ WebkitTransform: 'rotate(' + degree + 'deg)'}) .css({ '-moz-transform': 'rotate(' + degree + 'deg)'}) .css({'transform-origin': origin || 'bottom right'}) ; // To avoid to 'too much' recursion, we use a timeout let timer = setTimeout(function() { rotate(++degree); clearTimeout(timer); },5); } let Cadre = $('div#cadre') , curHandler = undefined , startPosX = 0 , startPosY = 0 ; /** * When user click down on a handler * => curHandler is defined => we work */ $('.handler').mousedown(function(ev){ startPosX = ev.pageX ; startPosY = ev.pageY ; $(this).addClass('clicked'); curHandler = $(this); }) /** * When user click up on a handler * => curHandler is undefined => stop work */ $('.handler').mouseup(function(ev){ $(this).removeClass('clicked'); curHandler = undefined ; }) /** * When user move the mouse * We only work when an handler (curHandler) is defined * Otherwise, we do nothing */ $('body').mousemove(function(ev){ if (curHandler) { // <= A handler is defined (click down) // => we rotate when mouse mouve angle = startPosX - ev.pageX ; // The rotation origin is set in the HTML Handler, but // we could get it from a JS constant or anything rotate(Cadre, curHandler.attr('data-origin'), angle); } }) })
div#cadre { width: 200px; height: 100px; background-color: darkblue; top: 50px; left: 100px; position: fixed; clear:both; } div.handler {position:absolute; width:5%;height:10px;background-color:red;} div.handler.clicked{background-color:green!important;} div.tl-handler {top:0; left:0;} div.tr-handler {top:0; right:0;} div.bl-handler {bottom:0; left:0;} div.br-handler {bottom:0; right:0;} div.mt-handler {top:0;left:47.5%;} div.mb-handler {bottom:0;left:47.5%;} div#explain {font-size:9.2pt;font-style:italic;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="explain">Click on the green handler to stop rotation (if any)</div> <div id="cadre"> <div class="handler tl-handler" data-origin="top left"></div> <div class="handler tr-handler" data-origin="top right"></div> <div class="handler bl-handler" data-origin="bottom left"></div> <div class="handler br-handler" data-origin="bottom right"></div> <div class="handler mt-handler" data-origin="50% top"></div> <div class="handler mb-handler" data-origin="50% bottom"></div> </div>
After that, you can play with <jQuerySet>.css({:width, :height})
to change the width and the height when mouse moves keeping the box angle. 之后,您可以使用
<jQuerySet>.css({:width, :height})
来更改鼠标移动时保持框角的宽度和高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.