180 degree rotated div is available on one side only

I got a rather strange problem. I have a div that can be rotated through CSS3. The div has a child div and a back child div, and the back div has -webkit-transform: rotateY( 180deg ) .

The problem is that as soon as the parent element is rotated to display the back of the div, it will detect clicks of the child elements on only one side of the div, in particular the second half of the div or the right side. The front of the front detects clicks over the entire surface of the element. In addition, z-indices are exact. I assume that the problem could be caused by the rotation, and the browser displays half the side β€œcloser”?

The code that breaks this is extremely complex, so I created a test file to demonstrate the problem below. I am using the jQuery plugin that I wrote for 3D transforms, which can be found here https://github.com/pwhisenhunt/jquery.transform/blob/master/jquery.transform.js .

Edit: After experiments, a click of a button element is registered only with 100-200 pixels, and not with 0-100 pixels. In other words, it is actually only registered in the second half of the div.

Any help is much appreciated!

 <html> <head> <style> .element{ width:200; height:200; -webkit-perspective: 800; -webkit-transform-style: preserve-3d; } .element figure { display: block; height: 100%; width: 100%; position: absolute; -webkit-backface-visibility: hidden; border:1px solid yellow; } .element .front { -webkit-border-radius:8px; padding: 0px; margin: 0px; background-color:yellow; z-index: 9870; } .element .back { -webkit-border-radius:8px; padding: 0px; margin: 0; -webkit-transform: rotateY( 180deg ); z-index: 0; border: 1px solid red; background-color:green; } </style> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script src="https://raw.github.com/pwhisenhunt/jquery.transform/master/jquery.transform.js"></script> <script> $(function(){ var temp = false; $(".element").click(function(){ if(temp == false){ $(this).transform("setAnimationDuration", 1).transform("rotateY", 180); $(this).unbind("mouseenter mouseleave"); button = $(document.createElement('div')).attr("id", "button").css({ width: 200, height: 50, backgroundColor:"blue" }); button.click(function(){ console.log("Clicking"); }); temp = true; $(this).append(button); } }) }) </script> </head> <body> <div class="element"> <figure class="front"></front> <figure class="back"></front> </div> </body> </html> 

JSFiddle An example of a problem - can be found HERE!

+4
source share
6 answers

it seems like you are missing a container (almost the same as I was missing it).

see official documentation

it is not an external element, but a shell inside it. which in turn causes the display of one of the two divs (and the transition to it)

+1
source

I know that for most of us this answer was too late, but today I ran into this problem, and none of the answers helped me solve this problem.

The @kristiankeane solution made the second half without clickability. I was using a wrapper container . It turns out that this is an odd error in webkit, and I was able to fix it and make 100% of the element clickable by changing the conversion: rotateY (180deg) to convert: rotateY (-180deg)

This is really strange, and I don’t know how it works, but it was. I hope this helps someone!

+10
source

I had the same problem, I was able to fix it by slightly changing the parent rotation when flipping - I changed

 `.flip-holder.flipped { -webkit-transform: rotateY(180deg); -moz-transform: rotateY(180deg); transform: rotateY(180deg); }` 

to

 `$.flip-holder.flipped { -webkit-transform: rotateY(180.5deg); -moz-transform: rotateY(180.5deg); transform: rotateY(180.5deg); }` 

and the entire back side (plus overflowing elements located absolutely) were now clickable, and the browser did not display an additional 0.5-inch rotation so that the text and images were clear.

+4
source

Move both front and back a little and they will not overlap.

Example:

  .element .front { -webkit-transform: translateZ(1px); } .element .back { -webkit-transform: rotateY(180deg) translateZ(1px); } 
+1
source

It may be (and I'm just thinking) that instead of the usual, you need to use the live or delegate event binding. I assume that the click event may be "remembered" in some way, like the starting position of a div without rotation.

0
source

After all the tricks are rotated on the back and rotated 180.5 and others ... the problem is fixed only as follows: When the rotation ends - create a new element, clone html from the rotated element and insert a new element instead of the old

0
source

Source: https://habr.com/ru/post/1385533/


All Articles