Rotating an HTML element with mouse (or mouseevent) with CSS zoom appliedAdding HTML entities using CSS contentHow to apply CSS to iframe?Convert HTML + CSS to PDF with PHP?Retrieve the position (X,Y) of an HTML elementHow to apply !important using .css()?CSS selector for first element with classHow can I set the default value for an HTML <select> element?Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQueryIs it possible to apply CSS to half of a character?Moving image with cursor (parent being transform/css rotated)

Double or Take game

Pressure inside an infinite ocean?

Why is Arya visibly scared in the library in S8E3?

How long would it take for people to notice a mass disappearance?

I have a unique character that I'm having a problem writing. He's a virus!

Verb "geeitet" in an old scientific text

Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?

How can I get a job without pushing my family's income into a higher tax bracket?

Prove that the limit exists or does not exist

Are there any Final Fantasy Spirits in Super Smash Bros Ultimate?

Missing Piece of Pie - Can you find it?

How to apply differences on part of a list and keep the rest

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

Can a nothic's Weird Insight action discover secrets about a player character that the character doesn't know about themselves?

Would glacier 'trees' be plausible?

Make some Prime Squares!

In Avengers 1, why does Thanos need Loki?

Set collection doesn't always enforce uniqueness with the Date datatype? Does the following example seem correct?

Why Isn’t SQL More Refactorable?

How wide is a neg symbol, how to get the width for alignment?

How was the quadratic formula created?

Can Infinity Stones be retrieved more than once?

Fitch Proof Question

Point of the the Dothraki's attack in GoT S8E3?



Rotating an HTML element with mouse (or mouseevent) with CSS zoom applied


Adding HTML entities using CSS contentHow to apply CSS to iframe?Convert HTML + CSS to PDF with PHP?Retrieve the position (X,Y) of an HTML elementHow to apply !important using .css()?CSS selector for first element with classHow can I set the default value for an HTML <select> element?Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQueryIs it possible to apply CSS to half of a character?Moving image with cursor (parent being transform/css rotated)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've found an example of rotating an HTML element in an old SO question:



http://jsfiddle.net/superasn/w48rsvp2/



Unforunatately as soon as I apply any zoom (style="zoom:0.5") to the parent element the rotation becomes wonky.



http://jsfiddle.net/superasn/mv2oqL36/2/ (with zoom of 0.5 and offset of 500px on parent element)



The code for rotation is like this



$(document).ready(function() 
// the same as yours.
function rotateOnMouse(e, pw)
var offset = pw.offset();
var center_x = (offset.left) + ($(pw).width() / 2);
var center_y = (offset.top) + ($(pw).height() / 2);
var mouse_x = e.pageX;
var mouse_y = e.pageY;
var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
var degree = (radians * (180 / Math.PI) * -1) + 100;
// window.console.log("de="+degree+","+radians);
$(pw).css('-moz-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-webkit-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-o-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-ms-transform', 'rotate(' + degree + 'deg)');


$('.drop div img').mousedown(function(e)
e.preventDefault(); // prevents the dragging of the image.
$(document).bind('mousemove.rotateImg', function(e2)
rotateOnMouse(e2, $('.drop div img'));
);
);

$(document).mouseup(function(e)
$(document).unbind('mousemove.rotateImg');
);
);


I think the rotateOnMouse function needs to factor the CSS zoom of parent somehow but I can't figure it out.



My questions is what changes I need to make in rotateOnMouse function to calculate degree variable after zoom?










share|improve this question
























  • P.S. I've tried diving center_x and center_y with zoom (so center_x/2 for zoom 0.5) and it makes it work a little but the rotation isn't very smooth.

    – supersan
    Mar 22 at 22:28






  • 1





    Updating the center during rotation made it wonky when hovering the image, even without the zoom. Seems to work better when defining it beforehand, accounting for the zoom level is rather simple - use it as an extra factor when calculating the center. Here's a demo.

    – Shikkediel
    Mar 22 at 23:50












  • thanks it does seem to work with the changes you've made!

    – supersan
    Mar 23 at 0:16






  • 1





    No problem, I noticed zoom doesn't actually work in Firefox but I don't see any real adverse effect either. Might be worth checking into though, possibly use scale instead.

    – Shikkediel
    Mar 23 at 0:20






  • 1





    Not as simple as I thought it was apparently, my earlier approach seemed to be working (and logical) but it was likely a fluke. The clue is actually in the pageX and pageY events I think. Demo here. It's pretty terrible on Firefox now though.

    – Shikkediel
    Mar 23 at 4:53


















0















I've found an example of rotating an HTML element in an old SO question:



http://jsfiddle.net/superasn/w48rsvp2/



Unforunatately as soon as I apply any zoom (style="zoom:0.5") to the parent element the rotation becomes wonky.



http://jsfiddle.net/superasn/mv2oqL36/2/ (with zoom of 0.5 and offset of 500px on parent element)



The code for rotation is like this



$(document).ready(function() 
// the same as yours.
function rotateOnMouse(e, pw)
var offset = pw.offset();
var center_x = (offset.left) + ($(pw).width() / 2);
var center_y = (offset.top) + ($(pw).height() / 2);
var mouse_x = e.pageX;
var mouse_y = e.pageY;
var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
var degree = (radians * (180 / Math.PI) * -1) + 100;
// window.console.log("de="+degree+","+radians);
$(pw).css('-moz-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-webkit-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-o-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-ms-transform', 'rotate(' + degree + 'deg)');


$('.drop div img').mousedown(function(e)
e.preventDefault(); // prevents the dragging of the image.
$(document).bind('mousemove.rotateImg', function(e2)
rotateOnMouse(e2, $('.drop div img'));
);
);

$(document).mouseup(function(e)
$(document).unbind('mousemove.rotateImg');
);
);


I think the rotateOnMouse function needs to factor the CSS zoom of parent somehow but I can't figure it out.



My questions is what changes I need to make in rotateOnMouse function to calculate degree variable after zoom?










share|improve this question
























  • P.S. I've tried diving center_x and center_y with zoom (so center_x/2 for zoom 0.5) and it makes it work a little but the rotation isn't very smooth.

    – supersan
    Mar 22 at 22:28






  • 1





    Updating the center during rotation made it wonky when hovering the image, even without the zoom. Seems to work better when defining it beforehand, accounting for the zoom level is rather simple - use it as an extra factor when calculating the center. Here's a demo.

    – Shikkediel
    Mar 22 at 23:50












  • thanks it does seem to work with the changes you've made!

    – supersan
    Mar 23 at 0:16






  • 1





    No problem, I noticed zoom doesn't actually work in Firefox but I don't see any real adverse effect either. Might be worth checking into though, possibly use scale instead.

    – Shikkediel
    Mar 23 at 0:20






  • 1





    Not as simple as I thought it was apparently, my earlier approach seemed to be working (and logical) but it was likely a fluke. The clue is actually in the pageX and pageY events I think. Demo here. It's pretty terrible on Firefox now though.

    – Shikkediel
    Mar 23 at 4:53














0












0








0








I've found an example of rotating an HTML element in an old SO question:



http://jsfiddle.net/superasn/w48rsvp2/



Unforunatately as soon as I apply any zoom (style="zoom:0.5") to the parent element the rotation becomes wonky.



http://jsfiddle.net/superasn/mv2oqL36/2/ (with zoom of 0.5 and offset of 500px on parent element)



The code for rotation is like this



$(document).ready(function() 
// the same as yours.
function rotateOnMouse(e, pw)
var offset = pw.offset();
var center_x = (offset.left) + ($(pw).width() / 2);
var center_y = (offset.top) + ($(pw).height() / 2);
var mouse_x = e.pageX;
var mouse_y = e.pageY;
var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
var degree = (radians * (180 / Math.PI) * -1) + 100;
// window.console.log("de="+degree+","+radians);
$(pw).css('-moz-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-webkit-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-o-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-ms-transform', 'rotate(' + degree + 'deg)');


$('.drop div img').mousedown(function(e)
e.preventDefault(); // prevents the dragging of the image.
$(document).bind('mousemove.rotateImg', function(e2)
rotateOnMouse(e2, $('.drop div img'));
);
);

$(document).mouseup(function(e)
$(document).unbind('mousemove.rotateImg');
);
);


I think the rotateOnMouse function needs to factor the CSS zoom of parent somehow but I can't figure it out.



My questions is what changes I need to make in rotateOnMouse function to calculate degree variable after zoom?










share|improve this question
















I've found an example of rotating an HTML element in an old SO question:



http://jsfiddle.net/superasn/w48rsvp2/



Unforunatately as soon as I apply any zoom (style="zoom:0.5") to the parent element the rotation becomes wonky.



http://jsfiddle.net/superasn/mv2oqL36/2/ (with zoom of 0.5 and offset of 500px on parent element)



The code for rotation is like this



$(document).ready(function() 
// the same as yours.
function rotateOnMouse(e, pw)
var offset = pw.offset();
var center_x = (offset.left) + ($(pw).width() / 2);
var center_y = (offset.top) + ($(pw).height() / 2);
var mouse_x = e.pageX;
var mouse_y = e.pageY;
var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
var degree = (radians * (180 / Math.PI) * -1) + 100;
// window.console.log("de="+degree+","+radians);
$(pw).css('-moz-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-webkit-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-o-transform', 'rotate(' + degree + 'deg)');
$(pw).css('-ms-transform', 'rotate(' + degree + 'deg)');


$('.drop div img').mousedown(function(e)
e.preventDefault(); // prevents the dragging of the image.
$(document).bind('mousemove.rotateImg', function(e2)
rotateOnMouse(e2, $('.drop div img'));
);
);

$(document).mouseup(function(e)
$(document).unbind('mousemove.rotateImg');
);
);


I think the rotateOnMouse function needs to factor the CSS zoom of parent somehow but I can't figure it out.



My questions is what changes I need to make in rotateOnMouse function to calculate degree variable after zoom?







javascript jquery html css css-transforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 2:46







supersan

















asked Mar 22 at 22:20









supersansupersan

1,8341838




1,8341838












  • P.S. I've tried diving center_x and center_y with zoom (so center_x/2 for zoom 0.5) and it makes it work a little but the rotation isn't very smooth.

    – supersan
    Mar 22 at 22:28






  • 1





    Updating the center during rotation made it wonky when hovering the image, even without the zoom. Seems to work better when defining it beforehand, accounting for the zoom level is rather simple - use it as an extra factor when calculating the center. Here's a demo.

    – Shikkediel
    Mar 22 at 23:50












  • thanks it does seem to work with the changes you've made!

    – supersan
    Mar 23 at 0:16






  • 1





    No problem, I noticed zoom doesn't actually work in Firefox but I don't see any real adverse effect either. Might be worth checking into though, possibly use scale instead.

    – Shikkediel
    Mar 23 at 0:20






  • 1





    Not as simple as I thought it was apparently, my earlier approach seemed to be working (and logical) but it was likely a fluke. The clue is actually in the pageX and pageY events I think. Demo here. It's pretty terrible on Firefox now though.

    – Shikkediel
    Mar 23 at 4:53


















  • P.S. I've tried diving center_x and center_y with zoom (so center_x/2 for zoom 0.5) and it makes it work a little but the rotation isn't very smooth.

    – supersan
    Mar 22 at 22:28






  • 1





    Updating the center during rotation made it wonky when hovering the image, even without the zoom. Seems to work better when defining it beforehand, accounting for the zoom level is rather simple - use it as an extra factor when calculating the center. Here's a demo.

    – Shikkediel
    Mar 22 at 23:50












  • thanks it does seem to work with the changes you've made!

    – supersan
    Mar 23 at 0:16






  • 1





    No problem, I noticed zoom doesn't actually work in Firefox but I don't see any real adverse effect either. Might be worth checking into though, possibly use scale instead.

    – Shikkediel
    Mar 23 at 0:20






  • 1





    Not as simple as I thought it was apparently, my earlier approach seemed to be working (and logical) but it was likely a fluke. The clue is actually in the pageX and pageY events I think. Demo here. It's pretty terrible on Firefox now though.

    – Shikkediel
    Mar 23 at 4:53

















P.S. I've tried diving center_x and center_y with zoom (so center_x/2 for zoom 0.5) and it makes it work a little but the rotation isn't very smooth.

– supersan
Mar 22 at 22:28





P.S. I've tried diving center_x and center_y with zoom (so center_x/2 for zoom 0.5) and it makes it work a little but the rotation isn't very smooth.

– supersan
Mar 22 at 22:28




1




1





Updating the center during rotation made it wonky when hovering the image, even without the zoom. Seems to work better when defining it beforehand, accounting for the zoom level is rather simple - use it as an extra factor when calculating the center. Here's a demo.

– Shikkediel
Mar 22 at 23:50






Updating the center during rotation made it wonky when hovering the image, even without the zoom. Seems to work better when defining it beforehand, accounting for the zoom level is rather simple - use it as an extra factor when calculating the center. Here's a demo.

– Shikkediel
Mar 22 at 23:50














thanks it does seem to work with the changes you've made!

– supersan
Mar 23 at 0:16





thanks it does seem to work with the changes you've made!

– supersan
Mar 23 at 0:16




1




1





No problem, I noticed zoom doesn't actually work in Firefox but I don't see any real adverse effect either. Might be worth checking into though, possibly use scale instead.

– Shikkediel
Mar 23 at 0:20





No problem, I noticed zoom doesn't actually work in Firefox but I don't see any real adverse effect either. Might be worth checking into though, possibly use scale instead.

– Shikkediel
Mar 23 at 0:20




1




1





Not as simple as I thought it was apparently, my earlier approach seemed to be working (and logical) but it was likely a fluke. The clue is actually in the pageX and pageY events I think. Demo here. It's pretty terrible on Firefox now though.

– Shikkediel
Mar 23 at 4:53






Not as simple as I thought it was apparently, my earlier approach seemed to be working (and logical) but it was likely a fluke. The clue is actually in the pageX and pageY events I think. Demo here. It's pretty terrible on Firefox now though.

– Shikkediel
Mar 23 at 4:53













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308512%2frotating-an-html-element-with-mouse-or-mouseevent-with-css-zoom-applied%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308512%2frotating-an-html-element-with-mouse-or-mouseevent-with-css-zoom-applied%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현