For visualization of the intended effect, go near the bottom of this site, at the "Catering Services" section, and hover over the three images.
I want my images, on hover, to zoom-in -- increase in height and width -- while the frame around it shrinks, with overflow:hidden ofcourse.
Here's what I have written so far:
<style type="text/css">
.container {
float: left;
width: 50%;
margin: 0 auto;
}
.frame {
width: 80%;
height: 50%;
overflow: hidden;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.frame:hover {
width: 70%;
height: 45%;
}
.frame > img {
width: 100%;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.frame:hover {
width: 120%;
}
</style>
<div class="container">
<div class="frame">
<img src="http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg" alt="Image of a dumb cat sitting on a laptop" title="get off my laptop" />
</div>
</div>
<!---End of container-->
The height of the frame is shrinking but not the width. Moreover, I want the image to expand on all four sides, and the frame to shrink likewise. Can this be achieved with something other than transitions? Any suggestions or tips on how should I go about solving this?
Just animate the img's transform:scale() and you should be all set.
Hope it helps!
.container {
float: left;
width: 50%;
margin: 0 auto;
}
.frame {
width: 80%;
height: 50%;
overflow: hidden;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.frame:hover {
width: 70%;
height: 45%;
}
.frame > img {
width: 100%;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.frame:hover img {
transform: scale(2);
}
<div class="frame">
<img src="http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg" alt="Image of a dumb cat sitting on a laptop" title="get off my laptop" />
</div>
Related
I'm trying to make two images crossfade when you hover over them, and it works besides the fact that it hides the text I need. The text should be under the image instead of behind it. How can I fix this?
#center {
text-align: center;
}
#under {
text-align: center;
margin: 0;
max-width: 50%;
margin-left: auto;
margin-right: auto;
}
#crossfade {
position: relative;
}
#crossfade img {
position: absolute;
left: 0;
opacity: 1;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#crossfade img.top:hover {
opacity: 0;
}
img {
margin-right: 3%;
max-width: 65%
}
#goofy {
margin: 0;
margin-bottom: 40px;
}
<div id="center">
<div id="crossfade">
<img id="goofy" src="https://inpulse.eli328.repl.co/half.png" alt="half" class="bottom">
<img id="goofy" src="https://inpulse.eli328.repl.co/active.png" alt="active" class="top">
</div>
<p id="under">
The Inpulse creates a powerful electric charge that when reaching sufficient levels, creates a bright arc of lightining between the two prongs. The handheld device will definitely satisfy its user.
</p>
</div>
Give #crossfade width & height.
#center {
text-align: center;
}
#under {
text-align: center;
margin: 0;
max-width: 50%;
margin-left: auto;
margin-right: auto;
}
#crossfade {
position: relative;
width: 500px;
height: 330px;
}
#crossfade img {
position: absolute;
left: 0;
opacity: 1;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#crossfade img.top:hover {
opacity: 0;
}
img {
margin-right: 3%;
max-width: 65%
}
#goofy {
margin: 0;
margin-bottom: 40px;
}
<div id="center">
<div id="crossfade">
<img id="goofy" src="https://inpulse.eli328.repl.co/half.png" alt="half" class="bottom">
<img id="goofy" src="https://inpulse.eli328.repl.co/active.png" alt="active" class="top">
</div>
<p id="under">
The Inpulse creates a powerful electric charge that when reaching sufficient levels, creates a bright arc of lightining between the two prongs. The handheld device will definitely satisfy its user.
</p>
</div>
How can i make the picture zoom in with CSS when my picture is 100% width in a bootstrap column? With my code below, it seems to transition outside the frame.
.frame {
width: 100%;
height: 75%
overflow: hidden;
}
.zoomin img {
width: 100%;
height: 75%
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.zoomin img:hover {
width: 105%;
}
<div class="col-md-3">
<div class="zoomin frame">
<img src="http://lorempixel.com/400/200/abstract/1/" title="" />
</div>
</div>
You don't need change your image size, you can set transform: scale to zoom them.
.frame {
width: 100%;
height: 100%
overflow: hidden;
}
.zoomin img {
width: 100%;
height: 100%
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.zoomin img:hover {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
<div class="col-md-3">
<div class="zoomin frame">
<img src="http://lorempixel.com/400/200/abstract/1/" title="" />
</div>
</div>
I have two boxes. When clicking a button, the left box is supposed to get smaller and the right box bigger. I am aiming at having a smooth transition. When the right box gets bigger, I want a margin right to be included.
I use CSS3 transition effect. How can I achieve that for the right box the width and margin right transitions happen simultaneously and correctly?
JS Fiddle:
http://jsfiddle.net/bmzw80py/4/
My code:
HTML:
<div class="container">
<div class="box-left"></div>
<div class="box-right"></div>
</div>
<button id="animate">Animate</button>
CSS:
.container {
width: 100%;
height: 200px;
padding: 40px 0 0 60px;
}
.box-left {
float: left;
width: 60%;
height: 100px;
background: blue;
}
.box-left-smaller {
-webkit-transition: width 1s ease-in-out;
-moz-transition: width 1s ease-in-out;
-o-transition: width 1s ease-in-out;
transition: width 1s ease-in-out;
width: 355px;
}
.box-right {
float: right;
width: 30%;
height: 100px;
background: orange;
}
.box-right-bigger {
-webkit-transition: width 1s ease-in-out;
-moz-transition: width 1s ease-in-out;
-o-transition: width 1s ease-in-out;
transition: width 1s ease-in-out;
-webkit-transition: margin 1s ease-in-out;
-moz-transition: margin 1s ease-in-out;
-o-transition: margin 1s ease-in-out;
transition: margin 1s ease-in-out;
width: 62%;
margin-right: 80px;
}
JS:
$('#animate').click(function() {
$('.box-left').addClass('box-left-smaller');
$('.box-right').addClass('box-right-bigger');
});
There's no need to trigger two different transitions: you might just change the width and the left margin of the left box by applying one class only e.g.
http://jsfiddle.net/4qwrLtuw/1/
CSS (all)
.container {
width: 100%;
height: 200px;
padding: 40px 0 0 0;
}
.box-right {
overflow: hidden;
height: 100px;
background: orange;
}
.box-left {
float: left;
width: 60%;
margin-right: 2%;
height: 100px;
background: blue;
}
.box-left-smaller {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
width: 30%;
margin-right: 80px;
}
Result
You need transition margin first then width
.box-right-bigger {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
width: 62%;
margin-right: 80px;
}
from .box-right-bigger class
Fiddle
Use 1 translation for both animations by using all instead of 2 declaration (one for width, one for margin):
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
In your case, the first transition declaration (width) is overriden by the transition for margin...
FIDDLE : http://jsfiddle.net/bmzw80py/11/
Well, you might start out transitioning one or two properties, but then decide to add some others that you want transitioned. So, if the other transition-related values are the same, then it would be much easier to just have the “all” keyword in there from the start, so you don’t have to specify each property in a comma-separated list.
$('#animate').click(function() {
$('.box-left').addClass('box-left-smaller');
$('.box-right').addClass('box-right-bigger');
});
.container {
width: 100%;
height: 200px;
padding: 40px 0 0 60px;
}
.box-left {
float: left;
width: 60%;
height: 100px;
background: blue;
}
.box-left-smaller {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
width: 30%;
}
.box-right {
float: right;
width: 30%;
height: 100px;
background: orange;
}
.box-right-bigger {
width: 62%;
margin-right: 80px;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="box-left"></div>
<div class="box-right"></div>
</div>
<button id="animate">Animate</button>
Here,you find demo
https://jsfiddle.net/DhwaniSanghvi/mr1feb5f/
Me and my friend recently have a problem with a portfolio case, the hove over animation doesnt go back properly to the original picture. How can we fix this?
See: The website
<div class="col-md-3 col-sm-6">
<div class="case">
<img src="img/2.jpg" class="img-responsive">
<div class="case_content">
<div class="case_text">
<h3>Market Download Buttons</h3>
<h4>UI Design</h4>
</div>
<a class="venobox" href="img/2.jpg"><p class="balk">View Dribbble Shot</p></a>
</div>
</div>
</div>
.cases {
max-width: 100%;
padding: 0;
}
.case {
overflow: hidden;
position: relative;
}
.case_content {
background-color: rgba(54,54,62,0.99);
position: absolute;
bottom: -100%;
width: 100%;
height: 100%;
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
-o-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-ms-transition: all 0.6s ease;
opacity: 1;
}
.case_text {
width: 80%;
padding: 0 0 0 5%;
}
Try using the hover option in CSS
.case {
..
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
-o-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-ms-transition: all 0.6s ease;
..
}
.case:hover, .case:hover .case_content {
display: block;
}
.case_content {
..
display: none;
..
}
I followed a tutorial exactly and instead of fading from the Print_tab.png to the Print_tab_hover.png,
it just fades to white. Any way I could fix this (without using javascript)?.
Here is the code i Used:
HTML:
<div id="print"
<img class="bottom" src="images/print_tab_hover.png" />
<img class="top" src="images/print_tab.png" />
</div>
CSS:
#print {
position:relative;
width: 300px;
height: 169px;
margin: 0 auto;
}
#print img {
position: absolute;
left: 0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#print img.top:hover {
opacity: 0;
}
This works:
#print {
position:relative;
width: 200px;
height: 120px;
margin: 0 auto;
background-image: url(http://fc06.deviantart.net/images2/i/2004/07/e/7/Firefox_dock_icon.png);
}
#print img {
position: absolute;
left: 0;
width: 200px;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#print img.top:hover {
opacity: 0;
}
<div id="print">
<img class="top" src="http://lanscaping-ideas.com/wp-content/uploads/2012/04/Landscape-Paintings-2.jpg" />
</div>
Just set a default background for the #print and fade over the new image, or vise versa.