Wordpress gallery change images on mouse over - css

Hi I have to show a grid of images; every item in the grid is a different product and it has 2-3 images but only the first image should be visible. On mouse hover should loop the other images. How can I do this in wordpress?
I thought to insert a gallery for every product and from css display only the first child and display:none all the other images. But now I don't know how to add slide on mouse over.
Any other solution?
thank you

According to the provided snippet, this is the CSS that should do the job.
In your sample, I just added a wrapper div, that will be our viewport (meaning the container that will just display one image at a time).
I also removed all the br that clear the float, as the CSS uses the float to display all images side by side for the slide.
<div id="viewport">
<div id="gallery-1" class="gallery galleryid-20 gallery-columns-1 gallery-size-collection">
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<a data-lightbox-gallery="lightbox-gallery-1" href="image1.jpg" data-rel="lightbox-gallery-1">
<img id="image1" style="border: medium none;" class="attachment-collection" alt="image1" height="420" width="300">
</a>
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<a data-lightbox-gallery="lightbox-gallery-1" href="image2.jpg" data-rel="lightbox-gallery-1">
<img id="image2" style="border: medium none;" class="attachment-collection" alt="image2" height="420" width="300">
</a>
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<a data-lightbox-gallery="lightbox-gallery-1" href="image3.jpg" data-rel="lightbox-gallery-1">
<img id="image3" style="border: medium none;" class="attachment-collection" alt="image3" height="420" width="300">
</a>
</dt>
</dl>
</div>
</div>
Note that I added some ids for all images just to have different colors through the CSS
Now, related to the CSS part:
/* THIS IS JUST FOR STYLING FAKE IMAGES, NOT PART OF THE SOLUTION */
#image1{background-color: red;}
#image2{background-color: green;}
#image3{background-color: blue;}
#viewport{width: 300px; overflow: hidden;}
#gallery-1{width: 900px; height: 420px; white-space: nowrap;}
#gallery-1 dl{float: left; margin: 0;}
/* ON HOVER, JUST TRIGGER ANIMATION WITH KEY FRAME TO PERFORM SLIDE AND PAUSE */
#viewport:hover #gallery-1{
-webkit-animation-name: slide;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: ease-in;
-webkit-animation-iteration-count: infinite;
}
/* ANIMATION ON 4S, PERCENTAGE OF THE ANIMATION HAS SAME VALUES TO MIMIC PAUSE ON ONE IMAGE */
#-webkit-keyframes slide
{
0% { transform: translateX(0); }
15% { transform: translateX(-300px); }
35% { transform: translateX(-300px); }
50% { transform: translateX(-600px); }
70% { transform: translateX(-600px); }
85% { transform: translateX(0); }
100% { transform: translateX(0); }
}

Related

css transform origin gets overwritten with rotate

I'm looking into CSS transforms and I cant get this one part to work.
#photo-container img {
transition: transform 2s, transform-origin 2s;
}
#container-1 img:hover {
transform: rotate(45deg);
transform-origin: 0 0;
}
#container-2 img:hover {
transform: rotate(1.5turn);
transform-origin: 50%, 50%;
}
#container-3 img:hover {
transform: scale(1.5);
transform-origin: 0 0;
}
<div class="photo-container" id="container-1">
<div class="photo">
<img src="http://placehold.it/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
The three classes HTML elements are the same as the one posted below.
My question is that say I change the transform origin to 0 0, and it has a transform set to rotate, when the rotate occurs and finishes, instead of returning to its original position the same way it did to get there, it recenters itself, then goes to that point that was specified in the rotate function and does it from there.
Is there something I missed here or is this the normal functionality?
Edit. i stuffed something up. sorry to bother
Try to add transform-origin to images without hover. And change #photo-container to .photo-container I can't see another problem with it.
.photo-container {
display: inline-block;
}
.photo-container img {
transition: transform 2s, transform-origin 2s;
transform-origin: 0 0;
}
#container-1 img:hover {
transform: rotate(45deg);
}
#container-2 img:hover {
transform: rotate(1.5turn);
}
#container-3 img:hover {
transform: scale(1.5);
}
<div class="photo-container" id="container-1">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
<div class="photo-container" id="container-2">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
<div class="photo-container" id="container-3">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>

animation happening over 2 background images

I have 2 images which I'm trying to make as my background image. I want those images to fade in and fade out after 2 seconds. At present the change in the background image is happening when I hover over the image. How can I make this change happen automatically, without any hover?
.bground {
width:100%;
position:relative;
background: url(../img/bg1.jpg) no-repeat top center;
-webkit-transition-property: background;
-webkit-transition-duration: 1s;
}
.bground:hover {
background: url(../img/bg2.jpg) no-repeat top center;
}
<section id="bground" class="bground">
<div class="display">
<img src="img/logo.png" alt="Logo">
</div>
<div class="page-scroll">
<a href="#about" class="btn btn-circle" style="color:#000000">
<i class="fa fa-angle-double-down animated"></i>
</a>
</div>
</section>
You can use animation property
I've do this code for you (with some img):
.bground {
width: 200px;
height: 200px;
position:relative;
background: url("http://www.bizreport.com/2011/02/03/android-logo-200x200.jpg") no-repeat top center;
-webkit-animation: 4s linear 0s infinite alternate test;
-o-animation:4s linear 0s infinite alternate test;
animation:4s linear 0s infinite alternate test;
}
#keyframes test {
0% {background-image: url("http://tech21info.com/admin/wp-content/uploads/2013/03/chrome-logo-200x200.png");}
100% {background-image: url(http://www.bizreport.com/2011/02/03/android-logo-200x200.jpg");}
}
<section id="bground" class="bground">
<div class="display">
</div>
<div class="page-scroll">
<a href="#about" class="btn btn-circle" style="color:#000000">
<i class="fa fa-angle-double-down animated"></i>
</a>
</div>
</section>

CSS Animation doesn't go away instantly

I have a component that needs to slide in from left with an animation. But I need the same component to disappear instantly. But with the following code, the component comes in with the animation I want, but takes 2 seconds to disappear. How should I change this, so the component would disappear instantly?
#keyframes slide-in {
from {left: -350px;}
to {left: 0;}
}
.how {
position: relative;
animation-name: slide-in;
animation-duration: 2s;
}
for the component to disappear, I am using an ng-if (AngularJS).
<div class="m-b col-md-6 how">
<p ng-if="active==1;" class="how"> First </p>
<p ng-if="active==2;" class="how"> Second </p>
<p ng-if="active==3;" class="how"> Third </p>
<p ng-if="active==4;" class="how"> Forth</p>
</div>
And here is the code that actually modifies the value of active:
<div class="m-b col-md-6">
<div class="m-b">
<butto ng-click="active=1;"> Step 1</button>
</div>
<div class="m-b">
<button ng-click="active=2;">Step 2</button>
</div>
<div class="m-b">
<button ng-click="active=3;">Step 3</button>
</div>
<div class="m-b">
<button ng-click="active=4;">Step 4</button>
</div>
</div>
So the component does disappear with the code above, but it takes 2 seconds for it to disappear!
To make an element visually disappear, you can set the opacity to 0. The element will still occupy space on the page.
JSFiddle
#keyframes slide-in {
0% {left: -350px; opacity: 1;}
99% {left: 0; opacity: 1;}
100% {left: 0; opacity: 0;}
}
.how {
opacity: 0;
position: relative;
animation-name: slide-in;
animation-duration: 2s;
}

Darken image in div on hover, but not another child image

On hover, I'm trying to change the opacity of the main parent to darken the main image, but I want to show another image over it in full opacity. Here's what I tried, but it's not working.
<div class="masonry-item">
<div class="masonry-item1">
<a href="#" class="image">
<div class="caption">
<h3><img src="blah" /></h3> <!-- DARKEN THIS -->
</div>
<img src="blah" /> <!-- KEEP FULL OPACITY -->
</a>
</div>
</div>
my css:
.masonry-container .masonry-item .image:hover .caption {
opacity: 1;
}
.masonry-container .masonry-item a.image:hover img {
opacity: .2; /* this seems to darken everything, but when removed darkening doesn't work */
}
.masonry-container .masonry-item1:hover {
background-color: rgba(222,222,222,.5);
z-index:98;
}
Here's an example of what I'm trying to do:
http://screencast.com/t/7qDUmCJMNd
Are you looking for something like this?:
See JSFiddle
HTML:
<div class="masonry-item">
<div class="masonry-item1">
<div class="caption">
<h3><img id="image1" src="http://images.visitcanberra.com.au/images/canberra_hero_image.jpg" /></h3> <!-- DARKEN THIS -->
</div>
<img id="image2" src="http://laurafranksblog.files.wordpress.com/2013/04/storymaker-best-hubble-space-telescope-images-20092-514x268.jpg" /> <!-- KEEP FULL OPACITY -->
</div>
</div>
CSS:
.masonry-item1 {
background-color: #000;
position: relative;
height: 500px;
}
.masonry-item1:hover #image1 {
opacity: .2;
transition: all 1s;
}
/* This is just to get the images to overlap, you don't need this if you're doing it another way */
#image1, #image2 {
position: absolute;
}
Here is my solution. Although there is no darken, I believe you could make it as #mikelt21's answer.
<div class="masonry-item">
<img id="i1" src="https://cdn0.iconfinder.com/data/icons/business-and-finance-9/250/vector_265_07-01-128.png" />
<img id="i2" src="https://cdn0.iconfinder.com/data/icons/business-and-finance-9/250/vector_265_20-01-128.png" />
</div>
<style>
img{
position: absolute;
top:0;
left:0;
transition: all 1s;
}
div:hover #i1{
opacity:1;
}
div:hover #i2{
opacity:0;
}
#i1{
opacity:0;
}
#i1:hover{
opacity:1;
}
</style>
Here is the example in action

I need to stack these two divs on top of each other while maintaining the content positions

I need to stack these two divs on top of each other but am having trouble finding a way to make it possible. I need to keep al the text inside in the same positions but need to be able to have the divs sit on top of one and other without setting absolute positions for them.
Here is what I have...
<body>
<div style="position:relative;">
<div style="position:absolute">
<p style="width: 762px; left:193px;" class="large-bold-font">hello hello helloT</p>
<p id="Customer.Description" style="left: 397px; top: 45px;" class="small-font"></p>
</div>
</div>
<div style="position:relative;">
<div style="position:absolute">
<p style="width: 762px; left:193px;" class="large-bold-font">hello hello helloT</p>
<p id="Customer.Description" style="left: 397px; top: 45px;" class="small-font"></p>
</div>
</div>
</body>
You should put the content of both your divs inside an outer div which has "position:relative", and put absolute positioning on your inner divs, and add a z-index to each of them. Then the larger z-index is placed over the smaller one.
<body>
<div style="position:relative;">
<div style="position:absolute;z-index:0;">
<p style="width: 762px; left:193px;" class="large-bold-font">hello hello helloT</p>
<p id="Customer.Description" style="left: 397px; top: 45px;" class="small-font"></p>
</div>
<div style="position:absolute;z-index:1;">
<p style="width: 762px; left:193px;" class="large-bold-font">hello hello helloT</p>
<p id="Customer.Description" style="left: 397px; top: 45px;" class="small-font"></p>
</div>
</div>
</body>
Perhaps this simple example will help you:
Link to fiddle
<body>
<div class="one">
Content one
</div>
<div class="two">
Content two
</div>
</body>
CSS:
.one{
color:red;
position:absolute;
left:0;
top:0;
z-index:2;
}
.two{
color:blue;
position:absolute;
left:0;
top:0;
z-index:1;
}
By positioning both divs absolutely, we can then use the left and top properties, set them to the same left and top positions (it can be in pixels, percent, etc), and then determine which one should be placed on top of the other by varying the z-index. The higher z-index numbered div will be the one on top, so the .one div will be on top and you will see more red than blue. Swap the values around so that .one has z-index:1 and .two has z-index:2, and you will see more blue (since those are the font colours).
From here, you can put the rest of your content into the divs in my example.
You have a couple options:
Use absolute postions on your divs. http://jsfiddle.net/sUyS3/1/
You could use negative margins on your second div.
<div style="margin-top: -25px;">
The best way to do so is by using CSS grid.
This is a blog post explaining how to achieve this: https://zelig880.com/how-to-stack-two-elements-on-top-of-each-other-without-using-position-absolute
And this is a codepen with a live example:https://codepen.io/zelig880/pen/oNdZWNa
Quick code:
.container_row{
display: grid;
}
.layer1, .layer2{
grid-column: 1;
grid-row: 1;
}
.layer1{
color: blue;
background: red;
animation-direction: reverse;
}
.layer2{
color: white;
background: blue;
}
.layer1, .layer2 {
animation-name: fade;
animation-duration: 10s;
}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="container_row">
<div class="layer1">
I am the layer behind
</div>
<div class="layer2">
I am actually on top
</div>
</div>
<div class="container_row">
Yuppi! This line is positioned successfully! This would not have been the case with position:absolute
</div>

Resources