Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

want to show the thickness of an element while it rotate

I am rotating a coin along Y axis by 90deg through CSS. Is there a way so that I can show the thickness of the coin after it have rotated, I thought I can scaleY after the coin have rotated along Y axis but this doesn't seem to work. Please suggest some way to do the same if it is possible. link_on_js fiddle for the same. Please use webkit browsers to open the link.

css

.coin {
    display: block;
    background: url("url-to-image-of-coin.jpg");
    background-size: 100% 100%;
    width: 100px;
    height: 100px;
    margin: auto;
    border-radius: 100%;
    transition: all 500ms linear;
}

.flip {
    transform: rotateY(180deg);
}

html

<div class="coin"></div>

jquery

$('.coin').click(function() {
    $(this).toggleClass('flip');
});

fiddle

http://jsfiddle.net/7EtLu/22/

like image 397
manyu Avatar asked Jul 25 '12 07:07

manyu


People also ask

Can I rotate in CSS?

The rotate CSS property allows you to specify rotation transforms individually and independently of the transform property. This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the transform property.

How do you rotate and translate in CSS?

translate() : Moves an element sideways or up and down. rotate() : Rotates the element clockwise from its current position. matrix() : A function that is probably not intended to be written by hand, but combines all transforms into one.

What is rotateY?

rotateY() The rotateY() CSS function defines a transformation that rotates an element around the ordinate (vertical axis) without deforming it. Its result is a <transform-function> data type.

What is Transformorigin?

Definition and Usage The transform-origin property allows you to change the position of transformed elements. 2D transformations can change the x- and y-axis of an element. 3D transformations can also change the z-axis of an element. To better understand the transform-origin property, view a demo.


1 Answers

You can use pseudo-elements to give an effect that is similar. Here is an example: http://jsfiddle.net/joshnh/y7rQL/

<div class="coin"></div>
body {
    transform: perspective(500px);
    transform-style: preserve-3d;
}
.coin {
    background-image: url("http://www.coolemails4u.com/wp-content/uploads/2010/10/indian_rupee.png");
    background-size: 100% 100%;
    border-radius: 100%;
    height: 100px;
    margin: 50px auto;
    position: relative;
    transition: .5s linear;
    transform-style: preserve-3d;
    width: 100px;
}
.coin:after {
    background-color: #262626;
    background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
    bottom: 0;
    content: '';
    left: 45px;
    position: absolute;
    top: 0;
    transform: rotateY(-90deg);
    transform-origin: 100% 50%;
    width: 5px;
    z-index: -10;
}
.coin:before {
    background-color: #262626;
    background-image: -webkit-linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
    border-radius: 100%;
    content: '';
    height: 100px;
    left: 0;
    position: absolute;
    top: 0;
    transform: translateZ(-5px);
    width: 100px;
}
.coin:hover {
    transform: rotateY(90deg);
}​

Also, here is a version that spins 180 degrees (it isn't quite as nice though): http://jsfiddle.net/joshnh/Bz22S/

like image 195
joshnh Avatar answered Oct 11 '22 22:10

joshnh