How to make an image inside a diamond shape morph to circle

user1788364

I've been experimenting a lot over the past couple of days with CSS and SVGs to try and achieve this effect.

I have a diamond shaped image and when the user hovers over it should morph into a circle and ideally the image should change to a block colour.

I thought at first I could do it using SVG and I managed to get an SVG diamond to morph into a circle but the next step was to have an image/block colour and I thought masks might be the way to go! The closest I got was: http://codepen.io/anon/pen/ByaaqE

HTML

<div>
  <span></span>
  <img src="http://img-fotki.yandex.ru/get/5607/5091629.6b/0_612e6_b9039c0d_M.jpg" alt="" />  
</div>

CSS

div {
    -webkit-clip-path: circle(100px at center);
    -moz-clip-path: circle(100px, 100px, 100px);
    clip-path: circle(100px, 100px, 100px);
    transition: all 0.3s ease;
    width: 200px; height: 300px;
}

div:hover {
    -webkit-clip-path: circle(40px at center);
    -moz-clip-path: circle(40px, 40px, 40px);
    clip-path: circle(40px, 40px, 40px);
}

span {
    display: block;
    width: 200px; height: 300px;
    background-color: red;
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 100;
    opacity: 0;
    transition: background-color 0.7s ease;
}

div:hover span {
    opacity: 1;
}

I could animate a circle but the moment I tried to make it a rectangle it wouldn't work (and I hadn't even managed to look at the diamond shape!).

I've also tried using a pure CSS method - although that comes with its own set of problems. I applied the styling on the img tag and it works how I want it but obviously the image is rotated. When I tried to put the image inside a div and rotate the image back to normal it had issues. When hovered over the image didn't go inside the circle despite having overflow hidden on the DIV.

http://codepen.io/anon/pen/jEOMem

It also has the problem of not having the overlay colour on hover.

I was wondering if anyone has managed to do this effect before and if they could shed some light on it and what my best options would be as I'm running out of ideas!

Turnip

This intrigued me so I thought I'd have a bash.

backface-visibility: hidden; is the key to preventing the image from overflowing it's parent as mentioned in your question.

You can use a pseudo element (:before) for your colour overlay:

/* FIRST EXAMPLE */
.wrap {
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  transform: rotate(-45deg);
  float: left;
  border: 1px solid red;
  margin: 150px 0 0 150px;
  overflow: hidden;
  transition: all 0.3s ease .3s;
  border-radius: 0px;
}
.morph {
  -webkit-transform: rotate(45deg) scale(1.5);
  -moz-transform: rotate(45deg) scale(1.5);
  transform: rotate(45deg) scale(1.5);
  float: left;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  backface-visibility: hidden;
}

.wrap:before {
  content: "";
  background: rgba(207, 0, 0, 0.5);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s ease;
}

.wrap:hover {
  border-radius: 50%;
}

.wrap:hover:before {
  transform: scale(1);
  opacity: 1;
} 
<div class="wrap"><img src="http://placekitten.com/g/300/300" class="morph"/>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to morph a SVG diamond into a circle

From Dev

How to draw an image inside Rounded Rectangle or inside a shape like circle?

From Dev

How to make ImageButton a circle and to fit Uploaded Image inside that circle?

From Dev

fabric.js : How to make an image in the shape of a circle with white borders

From Dev

How to display image in Diamond shape in iOS?

From Dev

iOS animate/morph shape from circle to square

From Dev

How to make diamond shape in html div using css3 without using background image...?

From Dev

How to make diamond shape in html div using css3 without using background image...?

From Dev

How would I create a title inside a diamond shape, with CSS?

From Dev

How would I create a title inside a diamond shape, with CSS?

From Dev

Rendering wrong Shape in libgdx? (Circle appearing as a diamond)

From Dev

How to make a java shape animate in a circle?

From Dev

How to crop image in a circle shape in Titanium?

From Dev

How to make an Image button circular and inside the circle,an image will be shown and a border will be there around the image

From Dev

How to make circle image in tcpdf?

From Dev

How to draw a diamond shape in java?

From Dev

How to create a 'transparent circle inside rectangle' shape in XML in Android?

From Dev

Diamond shape with rounded corners and background image

From Dev

Attempting a circular image, outputs a diamond shape?

From Dev

How to make an item drag inside a circle in QML?

From Dev

How to crop image inside the circle in UIImageView in iOS

From Dev

how stretch inside a circle image with nine patch

From Dev

Swift: Producing a circle UIView is giving a diamond like shape

From Dev

How to make a javafx button with circle shape of 3xp diameter?

From Dev

microsoft excel - how to fit image inside shape?

From Dev

How to make border for circle cropped image in glide

From Dev

How to make Circle image Label in Java?

From Dev

How to make the image transparent around the circle

From Dev

Morph circle to oval in openscad

Related Related

  1. 1

    How to morph a SVG diamond into a circle

  2. 2

    How to draw an image inside Rounded Rectangle or inside a shape like circle?

  3. 3

    How to make ImageButton a circle and to fit Uploaded Image inside that circle?

  4. 4

    fabric.js : How to make an image in the shape of a circle with white borders

  5. 5

    How to display image in Diamond shape in iOS?

  6. 6

    iOS animate/morph shape from circle to square

  7. 7

    How to make diamond shape in html div using css3 without using background image...?

  8. 8

    How to make diamond shape in html div using css3 without using background image...?

  9. 9

    How would I create a title inside a diamond shape, with CSS?

  10. 10

    How would I create a title inside a diamond shape, with CSS?

  11. 11

    Rendering wrong Shape in libgdx? (Circle appearing as a diamond)

  12. 12

    How to make a java shape animate in a circle?

  13. 13

    How to crop image in a circle shape in Titanium?

  14. 14

    How to make an Image button circular and inside the circle,an image will be shown and a border will be there around the image

  15. 15

    How to make circle image in tcpdf?

  16. 16

    How to draw a diamond shape in java?

  17. 17

    How to create a 'transparent circle inside rectangle' shape in XML in Android?

  18. 18

    Diamond shape with rounded corners and background image

  19. 19

    Attempting a circular image, outputs a diamond shape?

  20. 20

    How to make an item drag inside a circle in QML?

  21. 21

    How to crop image inside the circle in UIImageView in iOS

  22. 22

    how stretch inside a circle image with nine patch

  23. 23

    Swift: Producing a circle UIView is giving a diamond like shape

  24. 24

    How to make a javafx button with circle shape of 3xp diameter?

  25. 25

    microsoft excel - how to fit image inside shape?

  26. 26

    How to make border for circle cropped image in glide

  27. 27

    How to make Circle image Label in Java?

  28. 28

    How to make the image transparent around the circle

  29. 29

    Morph circle to oval in openscad

HotTag

Archive