I'm trying to combine fading out a colour (that part works fine) but also zoom in a background image smoothly on hover.
Wordpress is outputting the background image inline:
<a href="<?php echo the_permalink(); ?>" class="product-module" style="background-image:url(<?php echo the_field('thumbnail_image'); ?>);" data-equalizer-watch>
<span class="product-overlay">
<h2>
<?php echo get_the_title($post->post_parent); ?><br />
<?php echo the_title(); ?>
</h2>
</span>
</a>
And here's my css:
.product-module {
background-repeat: no-repeat;
background-size:cover;
background-position: center;
width:100%;
min-height:288px;
display:block;
position: relative;
transition:all 0.5s ease-out;
-webkit-transition:all 0.5s ease-out;
-o-transition:all 0.5s ease-out;
-moz-transition:all 0.5s ease-out;
}
.product-module:hover {
background-size:120%;
}
.product-module:hover h2 {
color:$orange;
}
.product-module h2 {
color:white;
font-size:2.375rem;
font-weight:$medium;
text-align: center;
height: 100%;
margin-bottom: 0px;
justify-content: center;
display: flex;
align-items: center;
padding:10px;
}
.product-overlay {
height:100%;
width:100%;
background-color:rgba(0,127,161,0.8);
display:block;
-webkit-transition: background .5s ease-out;
-moz-transition: background .5s ease-out;
-o-transition: background .5s ease-out;
transition: background .5s ease-out;
}
.product-overlay:hover {
background-color:rgba(0,127,161,0);
}
At the moment the colour fades out fine but the background image zoom jumps into place rather than it happening smoothly, how can I change that?
The problem is likely being caused by:
background-size:cover;
You should change your initial background-size to:
background-size: 100%;
Related
I can't share a page on this, due to the page not being public. However, what I'm trying to do is create a hover effect on both a div and a H4 text element. Nothing of which seems to work for me. Here's my code:
HTML:
<div class="grid__item small--one-half medium-up--one-quarter">
<a href="/collections/hoop-earrings" class="collection-item collection-item--overlaid" data-aos="row-of-4"><div class="image-wrap">
<div class="collection-image collection-image--square lazyload" style='background-position: center center; background-image: url("https://cdn.shopify.com/s/files/1/1810/9951/collections/LDE42DSOS_Hexagon_Hoop_Earring_web_scroll_1200x_ad647924-a6b9-4c9a-b36a-7d6a3b0d0a6c_720x.jpg?v=1561755337");'>
</div>
</div>
<noscript>
<div
class="collection-image collection-image--square"
style="background-image: url(//cdn.shopify.com/s/files/1/1810/9951/collections/LDE42DSOS_Hexagon_Hoop_Earring_web_scroll_1200x_ad647924-a6b9-4c9a-b36a-7d6a3b0d0a6c_400x.jpg?v=1561755337); background-position: center center;">
</div>
</noscript>
<div class="collection-image--overlay-background"></div>
<span
class="collection-item__title collection-item__title--overlaid collection-item__title--heading collection-item__title--center">
<span>
Text Goes Here
</span>
</span>
</a>
</div>
CSS:
.collection-image--overlay-background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #fff;
opacity: 0;
-webkit-transition: opacity 1s linear;
-moz-transition: opacity 1s linear;
-ms-transition: opacity 1s linear;
-o-transition: opacity 1s linear;
transition: opacity 1s linear;
}
.collection-item__title.collection-item__title--overlaid.collection-item__title--heading.collection-item__title--center {
opacity: 0!important;
-moz-transition: opacity .25s linear;
-webkit-transition: opacity .25s linear;
-o-transition: opacity .25s linear;
transition: opacity .25s linear;
}
#media only screen and (min-width: 768px) {
.collection-image--overlay-background:hover {
z-index: 1;
opacity: .8;
}
.collection-item__title.collection-item__title--overlaid.collection-item__title--heading.collection-item__title--center:hover {
z-index: 1;
opacity: 1;
}
}
I tried making a small snippet. See if it´s what you´re looking for.
Since you´re using the !important flag in one of your opacity rules, all the other changes after the fact will not take effect unless you also use !important. However I would not advice using !important that freely because whenever they are present such errors are a bit harder to track.
.container {
background-color: blue;
height: 100px;
}
.onHover {
background-color: red;
width: 80%;
height: 100px;
margin: 0 auto;
opacity: 0.5;
/*opacity: 0.5 !important; In your code you have
a line like this.*/
}
.onHover:hover {
opacity: 1;
}
<div class="container">
<div class="onHover">
<h4>My title Here</h4>
</div>
</div>
I have an album cover that also has a play button on top of it.
When a user hovers over the album cover, the opacity changes to lighten the image. Likewise, when hovering over the cover, if the user then hovers over the play button, the cover opacity should remain in it's changed state.
The problem is that because I have a transition effect on the opacity, the opacity flickers when hovering back and forth over the cover and the play button.
I created a fiddle to show the issue.
How can I have it so that when initially hovering over the album cover, the opacity transitions, but then hovering over the play button, the opacity simply stays the same without re-transitioning, causing it to flicker?
.play-button-container img:hover,
.play-button:hover + .image {
opacity: .6;
}
.play-button-container img {
transition: opacity .5s ease-out;
-moz-transition: opacity .5s ease-out;
-webkit-transition: opacity .5s ease-out;
-o-transition: opacity .5s ease-out;
}
.play-button {
position: absolute;
top: 10%;
left: 10%;
font-size: 30px;
color: #fff;
z-index: 1000;
background-color: red;
}
<div class="image-container">
<div class="play-button-container">
<div class="play-button">
PLAY
</div>
<div class="image">
<img src="http://papers.co/wallpaper/papers.co-am19-tycho-art-music-album-cover-illust-simple-white-40-wallpaper.jpg" width="350">
</div>
</div>
</div>
https://jsfiddle.net/659z2ndx/1/
When you hover over the play button, you change the opacity of the div with the class image. That is what causes the flicker.
What you should do is change the opacity of the img
.play-button-container img:hover,
.play-button:hover + .image > img {
opacity: .6;
}
.play-button-container img {
transition: opacity .5s ease-out;
-moz-transition: opacity .5s ease-out;
-webkit-transition: opacity .5s ease-out;
-o-transition: opacity .5s ease-out;
}
.play-button {
position: absolute;
top: 10%;
left: 10%;
font-size: 30px;
color: #fff;
z-index: 1000;
background-color: red;
}
<div class="image-container">
<div class="play-button-container">
<div class="play-button">
PLAY
</div>
<div class="image">
<img src="http://papers.co/wallpaper/papers.co-am19-tycho-art-music-album-cover-illust-simple-white-40-wallpaper.jpg" width="350">
</div>
</div>
</div>
.pic{
position: relative;
}
.pic .texthover{
position: absolute;
bottom:3%;
display: none;
z-index: 8000;
margin: 0 0 3.2px 0;
width: 100%;
text-align: left;
padding: 5px;
background: rgba(213,12,16,1.00);
border-bottom: 1px solid white;
transition: all 2s ease;
}
.pic:hover .texthover{
display: block;
}
<ul class="list-images">
<li>
<a href="#">
<div class="pic">
<img src="1 escultura.fw.png" width="278" height="175" title="Esculturas del Prado" class="image"/>
<div class="hover" style="">
<p class="texthover"> Escultura neoclasicista hasta el XVII</p>
</div> <!--END DIV HOVER-->
</div> <!--END DIV PIC-->
</li>
I've been racking my brain over this, it must be a very simple detail that escapes my comprehension, can anybody point it out??? Thanks all. I put the transition property in the original element and still not working...
A Vanila Example of Transition and how it works. You can change as per requirements.
div.list-images a:hover {
transition: background-color 0.5s linear;
-moz-transition: background-color 0.5s linear; /* Firefox 4 */
-webkit-transition: background-color 0.5s linear; /* Safari and Chrome */
-o-transition: background-color 0.5s linear; /* Opera */
-ms-transition: background-color 0.5s linear; /* Explorer 10 */
background:#ff0000;
}
<div class="list-images">transition</div>
I am experiencing an issue with CSS3 scaling and Safari (v10.0.1).
I have a selection of grid items with the following structure:
<div class="grid-inline col-12 bp1-col-6 bp3-col-3 index-grid-selector index">
<a href="">
<div class="index-grid-item">
<div class="index-grid-dummy"></div>
<img srcset=", 2x" title="" alt="">
</div>
</a>
</div>
CSS (LESS):
.index-grid-selector {
a {
.index-grid-item {
position: relative;
overflow: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
.index-grid-dummy {
padding-bottom: 100%;
}
img {
position: absolute;
top: 0;
left: 0;
-webkit-transition: all 0.25s ease-in-out;
-moz-transition: all 0.25s ease-in-out;
-ms-transition: all 0.25s ease-in-out;
-o-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
}
}
}
&:hover {
.index-grid-item {
img {
transform: scale(1.2);
-webkit-transition: all 0.25s ease-in-out;
-moz-transition: all 0.25s ease-in-out;
-ms-transition: all 0.25s ease-in-out;
-o-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
}
}
}
}
The image is positioned absolutely within the grid item container and then scaled on hover.
During the image scaling in Safari, the image enlarges slightly and appears to shift. Gaps (white lines) appear around the image. Once the animation is complete, the image sits correctly, until the hover function is removed.
I have set up a working demo here to showcase the issue.
http://www.testdomainone.co.uk/test.html
I have tried applying the folowing to the image and its parent, but the issue still occurs.
-webkit-transform-style: preserve-3d;
-webkit-transform:translate3d(0,0,0);
-webkit-transform: translateZ(0)
Does anyone know how this can be fixed?
This does not solve your specific issue using an img tag, though since you use fixed size for your images, why not use background-image
Updated with image-set to achieve the equivalent for background images as srcset does for img ... and since it is more or less only iOS Retina which use that high resolution, it will be a decent fallback for browser not supporting it
.index-grid-item {
position: relative;
overflow: hidden;
width: 200px;
height: 200px;
}
.index-grid-dummy {
padding-bottom: 100%;
background-size: 100%;
transition: transform 0.25s ease-in-out;
}
.index-grid-item:hover > div {
transform: scale(1.2);
transition: transform 0.25s ease-in-out;
}
<div class="index-grid-item">
<div class="index-grid-dummy" style="background-image: -webkit-image-set( url(http://www.testdomainone.co.uk/images/uploads/tours/39/jmc_5233-bigsur__thumb_large.jpg) 1x, url(http://www.testdomainone.co.uk/images/uploads/tours/39/jmc_5233-bigsur__thumb_large_2x.jpg) 2x );
background-image: url(http://www.testdomainone.co.uk/images/uploads/tours/39/jmc_5233-bigsur__thumb_large.jpg)"></div>
</div>
Side note, in above sample I use inline style to set the image source in the markup, as one does with the img tag, and of course this could be set in the CSS as well
This is the background image:
#logo
{background-image:url('logo.png');width:20px;height:23px;}
#logo:hover
{background-position:0 -23px;-webkit-transition: all 0.5s ease;}
#logo span
{margin-left:-3000px;}
<div id="logo"><span>logo</span></div>
This code gives me a slide effect (a vertical slide from the black S to the pink one) instead of the fade effect I'm looking for. Creating two images, would solve the issue, but that is not possible in this case.
How do I get the fade affect when using only one single image?
Try this - http://jsfiddle.net/Wds5z/4/
a, #logo {
background: url('http://i.stack.imgur.com/w5ZnN.png') 0 -23px;
width: 20px;
height: 23px;
display: block;
}
#logo {
background-position: 0 0;
-webkit-transition: opacity .5s linear;
-moz-transition: opacity .5s linear;
transition: opacity .5s linear;
}
#logo:hover {
opacity: 0;
}
#logo span {
margin-left:-3000px;
}