0

I'm trying to implement a 3D matrix transform on an image. The transform works correctly as I hover over the image. However, I can't seem to make it transition back to its original placement smoothly. When I leave the image after hovering it pops back into place quickly, not a smooth transition.

(Also, I'm trying to ultimately mirror this transition - to make the image bend to the right instead of the left...any ideas?)

Tried so many different solutions - any help would be great!

JSFiddle https://jsfiddle.net/0roefvye/

.rot {
  width: 100px;
  height: 100px;
  background-color: black;
}

.rot:hover {
  transform: matrix3d(0.9659258262890683, 0, 0.25881904510252074, 0, 0, 1, 0, 0, -0.25881904510252074, 0, 0.9659258262890683, 0, 0, 0, 0, 1);
  transition-delay: 0s;
  transition-duration: 2s;
  transition-timing-function: ease;
}

2 Answers 2

2

If you want same effect on mouse out then you should put all delay, timing function etc. on the actual class, not on hover.

.rot {
  width: 100px;
  height: 100px;
  background-color: black;
   transition-delay: 0s;
  transition-duration: 2s;
  transition-timing-function: ease;
}

.rot:hover {
  transform: matrix3d(0.9659258262890683, 0, 0.25881904510252074, 0, 0, 1, 0, 0, -0.25881904510252074, 0, 0.9659258262890683, 0, 0, 0, 0, 1);
 
}
<div class="rot"></div>

Sign up to request clarification or add additional context in comments.

4 Comments

MASSIVE thank you! Any idea on the values needed to transform the image to the right instead of to the left?
using matrix3d? then I need to dig Internet?
Yeh, using matrix3d - instead of moving to the left as it currently does, bending to the right.
the best way is to use online CSS tool for this.
1

By applying a transition to any pseudo-class, such as :hover, that transition will only be applied when the element is in the associated state.

To achieve what you want you would therefore need to apply the transition to the .rot class:

.rot {
  width: 100px;
  height: 100px;
  background-color: black;
  transition:transform 2s ease;
}
.rot:hover {
  transform: matrix3d(0.9659258262890683, 0, 0.25881904510252074, 0, 0, 1, 0, 0, -0.25881904510252074, 0, 0.9659258262890683, 0, 0, 0, 0, 1);
}
<div class="rot"></div>

As to the second part of your question, I'm not 100% sure on the exact effect you're attempting to achieve (could you edit your question to include an example?) but simply adding a transform-origin might do the trick for you:

.rot {
  width: 100px;
  height: 100px;
  background-color: black;
  transition: transform 2s ease;
  transform-origin: 0 0;
}
.rot:hover {
  transform: matrix3d(0.9659258262890683, 0, 0.25881904510252074, 0, 0, 1, 0, 0, -0.25881904510252074, 0, 0.9659258262890683, 0, 0, 0, 0, 1);
}
<div class="rot"></div>

3 Comments

Thank you SO much! Would you happen to know the values needed to create a transition to the right rather than the left?
Check the second Snippet I just added.
You're welcome :) If this has answered your question to your satisfaction, you might consider accepting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.