I recently had a web page to make which had to simple. Just some square images, floating on the page. Each image depicted a section of the website. However, as there was no text written on or under these images, to describe exactly what they stood for, I had to work out a way to have that description there for the reading, without disturbing the design.
Then I remember Google Plus. They have these boxes which flip. So, I decided to make something similar. This is basically what i was aiming for.
This is what is inside the box. This is the text that is to be shown when the box is turned around.
Basically, this can used in a gallery, or to make a menu with images and description hidden behind them, etc.
So, in words, this is what I need to have:
Also, the transition attribute gives the transformation, sometime to happen, making it slow and thus visible to the user.
Next comes the HTML part. This is basically, just the implementation of the elements that we needed and defined CSS for. No tricks here.
As the swing container and its contents are defined as class. You can use this element repeatedly to make up a whole page of items with it. The only attribute that you have to change here is the id of the swing-box.
Then I remember Google Plus. They have these boxes which flip. So, I decided to make something similar. This is basically what i was aiming for.
This is what is inside the box. This is the text that is to be shown when the box is turned around.
Basically, this can used in a gallery, or to make a menu with images and description hidden behind them, etc.
So, in words, this is what I need to have:
- An image which is shown initially
- A method to make that image flip and in process, change to a blank background
- A content that should appear inside the box when it is flipped.
Here is how it was achieved. First comes the CSS.
In the above CSS, the main ingredient was the transform attribute and the transition attribute. Defining the value of transform using the scaleX function, basically gives the box a scale along the X axis. This scale can even go in negative, which is something that we have used here.
- <style>
- #shekhoo-main-wrapper
- {
- width:100%;
- height:100%;
- display:inline-block;
- }
- .shekhoo-swing-container
- {
- width:300px;
- height:300px;
- margin:10px;
- float:left;
- }
- .shekhoo-swing-box
- {
- width:300px;
- height:300px;
- background-image:url(image.jpg);
- background-size:contain;
- -webkit-transition:all 1000ms;
- -moz-transition:all 1000ms;
- -o-transition:all 1000ms;
- transition:all 1000ms;
- }
- .shekhoo-swing-container:hover .shekhoo-swing-box
- {
- cursor:pointer;
- -webkit-transform:scaleX(-1);
- -moz-transform:scaleX(-1);
- -o-transform:scaleX(-1);
- transform:scaleX(-1);
- }
- .shekhoo-swing-container:hover .swing-inner
- {
- opacity:1.0;
- }
- .swing-inner
- {
- text-align:left;
- /*enable the text to be reverse-mirrored when the box flips */
- -webkit-transform:scaleX(-1);
- -moz-transform:scaleX(-1);
- -o-transform:scaleX(-1);
- transform:scaleX(-1);
- width:100%;
- height:100%;
- background-color:#9FC;
- opacity:0.0;
- -webkit-transition:all 1000ms;
- -moz-transition:all 1000ms;
- -o-transition:all 1000ms;
- transition:all 1000ms;
- }
- </style>
Also, the transition attribute gives the transformation, sometime to happen, making it slow and thus visible to the user.
Next comes the HTML part. This is basically, just the implementation of the elements that we needed and defined CSS for. No tricks here.
- <div id="shekhoo-main-wrapper" align="center">
- <div class="shekhoo-swing-container">
- <div class="shekhoo-swing-box" id="swingone" onmouseover="swingbox(this.id)" onmouseout="unswingbox(this.id)">
- <div class="swing-inner">
- <br />
- This is what is inside the box. This is the text that is to be shown when the box is turned around.<br />
- Basically, this can used in a gallery, or to make a menu with images and description hidden behind them, etc.
- </div>
- </div>
- </div>
As the swing container and its contents are defined as class. You can use this element repeatedly to make up a whole page of items with it. The only attribute that you have to change here is the id of the swing-box.
No comments:
Post a Comment