Making rollover between 2 images by hover - css

I'm using React and try to change 2 images by hovering them.
This is what I have done so far:
Card.js
<div className="image-wrapper">
<img src={sprites.front_default} className="image" alt="normal" />
<img src={sprites.back_default} className="image-hover" alt="hover" />
</div>
style.css
.image-wrapper {
position: relative;
}
.image-hover {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-out;
}
.image-hover:hover {
opacity: 1;
}
The main problem is that i want to make the front image opacity to 0 when im hovering the div, how can i make it?
I can make it without the fade changing but its important to make it with transition.
This is how I make it without transition
<img
className="figure"
src={sprites.front_default}
onMouseOver={(e) => (e.currentTarget.src = sprites.back_default)}
onMouseOut={(e) => (e.currentTarget.src = sprites.front_default)}
alt={"pokemon"}
/>

You can use just HTML & CSS. In the Card:
<div className="image-wrapper">
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png"
className="pokemon-image"
alt="normal"
/>
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/2.png"
className="pokemon-image pokemon-image--back"
alt="normal"
/>
</div>
Here, I've used one class pokemon-image to position the two images at the center of the image-wrapper element, and pokemon-image--back as the class that is showed when hovering over the image-wrapper element.
The CSS:
.image-wrapper {
width: 200px;
height: 150px;
background-color: #f7f7f7;
position: relative;
}
.pokemon-image {
position: absolute;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
.pokemon-image--back {
opacity: 0;
transition: opacity 1s ease-out;
}
.image-wrapper:hover .pokemon-image--back {
opacity: 1;
}
Hope this helps. You can try it in this codesandbox.

Related

CSS before with a transition

I want a transition on a wordpress menu item.
I plan to insert an icon before on hover...
Now I test this with a word and this works fine...
.academy .avia-menu-text:hover::before {
content:'Jetzt ';
transition:all 3s;
-webkit-transition:all 3s;
}
But the transition is not working. I need it with a smooth fade in. testfile
If I´m understanding your question correctly you want an annimated text before your element.
You can add this element without the hover state:
.academy .avia-menu-text:before {
width: 0;
transition: 3s;
content: 'your text';
}
.academy .avia-menu-text:hover:before {
width: 100%;
}
Here is a small example I made in a container
p:before{ content: 'hello world'; width: 0; display: block; overflow: hidden; transition: .3s; position: absolute; left: -100px; top: 0; white-space: nowrap;}
p:hover:before{ width: 100%; }
div{ width: 300px; height: 100px; }
p{ position: relative; left: 100px; }
<div>
<p>Text here</p>
</div>

Opacity transition not working with two fixed position elements

In my website, I have a YouTube-style progress bar (a thin line that is fixed to the top of the screen, loading from left to right) and a header over all of the content. Both of these elements have position: fixed.
When the page is finished loading, the progress bar gets opacity: 0. The progress bar has transition: opacity 0.4s, but it's not transitioning, just appearing and disappearing. This is my issue.
Here is an example of the issue: https://codepen.io/anon/pen/ZJNaqJ
Ideally, any solution would involve changing CSS within either .loader-outer or .loader... not #loader-wrapper. This is because I'm pulling in an external progress bar component (I'm using React) and I'd rather not re-implement it if I don't have to.
Thank you!
You can use css3 animation instead. If you want to trigger the animation at a specific event, add a style class name and set the animation attributes there. Then remove the style class name to stop the animation.
.wrapper {
width: 800px;
height: 400px;
background-color: lightblue;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: palevioletred;
z-index: 1;
height: 50px;
}
.loader-outer {
}
.loader-wrapper {
}
.loader {
background-color: lightpink;
height: 10px;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
animation-name:opacityAnimation;
animation-iteration-count: infinite;
animation-duration:2s;
}
#keyframes opacityAnimation {
0% {opacity:0;}
50% {opacity:1;}
100% {opacity:0;}
}
.content {
background-color: lightgreen;
}
<div class="wrapper">
<div>
<div class="header">
header stuff here
</div>
<div class="content">
body!
</div>
</div>
<div class="loader-outer">
<div id="loader-wrapper">
<div class="loader"></div>
</div>
</div>
</div>

Input image with :hover text and opacity

How can I make that the hover option allows me to see the image with opacity and the p tag inside not affected by opacity style? Please note that the img is inside an input tag and when I click it a bootsrap modal will appear with input form
.img_wrap:hover
#updateImg{ opacity: 0.7; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="img_wrap">
<input type='image' id='updateImg' src='http://placehold.it/350x150'>
</input>
<span></span><p class="imgText">Click here to change your image</p>
</div>
You need to handle each children's opacity separately. Also, if you want them overlapped, you need one of them (the text in my example, positioned absolute and the parent relative).
I'm guessing the following example does what you want to achieve? If not, please state your request clearer.
.img_wrap {
position: relative;
display: inline-block;
}
.img_wrap input[type="image"]{
opacity: 1;
display: block;
transition: opacity .3s cubic-bezier(.4,0,.2,1)
}
.img_wrap:hover input[type="image"] {
opacity: .3;
}
.img_wrap .imgText {
position: absolute;
height: 100%;
width: 100%;
left: 0;
top: 0;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
opacity: 0;
transition: opacity .3s cubic-bezier(.4,0,.2,1)
}
.img_wrap:hover .imgText {
opacity: 1;
pointer-events: none;
}
<div class="img_wrap">
<input type='image' id='updateImg' src='http://placehold.it/350x150' />
<div class="imgText">Click here to change your image</div>
</div>
Notes:
<input> is a self-closing tag, so <input></input> is invalid.
<input type="image"> is supposed to be used instead of a (submit) button. It's a shortcut for a button with a background image, that resizes itself to the image ratio. If you want to submit an image to the server using an <input>, you probably want to use <input type="file" />
here is what you want
.img_wrap{
display: inline-block;
position: relative;
}
.img_wrap:hover #updateImg{
opacity: 0.7;
position: relative;
}
.img_wrap:hover .imgText{
position:absolute;
top:0;
bottom: 0;
left: 0;
right:0;
}

Positioning a button on top of a canvas

I'm trying to position a font-awesome button on top of a canvas. My current markup:
<li id="container">
<i class="fa fa-plus"></i>
<canvas></canvas>
</li>
The container and the canvas are visible by default. When the user mouse-overs the container, the button also appears. However, it pushes the canvas downward, causing it to spill out of the container:
The container has position: absolute and I don't have any control over that (it's part of a plugin I'm using). I do have full control over the styling of the canvas and the button.
What makes this tricky is that the user can resize the container, and the button has to remain on the top center of it at all times. Currently that works fine, but I can't get it to also appear on top of the canvas.
Hover to see i.
*,
*:before,
*:after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #F72F4E;
}
#container {
position: absolute;
width: 50vmin;
height: 50vmin;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0,0,0,.2);
}
#container:hover i {
opacity: 1;
transition: opacity .2s ease-out;
}
#container i {
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 3;
text-align: center;
opacity: 0;
transition: opacity .2s ease-in;
}
#container canvas {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
border: 5px solid green;
}
<li id="container">
<i class="fa fa-plus">i</i>
<canvas></canvas>
</li>
Have you tried to utilize the z-index?
If you don't know what it is you can read up on it here: http://www.w3schools.com/cssref/pr_pos_z-index.asp
Essentially, you will have the button sit on top of all other elements.
Hope this gives some guidance.
Also! Just thought of this, try to mess around with the position property.
http://www.w3schools.com/cssref/pr_class_position.asp
The 'fixed' value will position your button relative to the DOM window, meaning other elements shouldn't have an effect on its position.
Resolved it by changing the font-awesome element to a div and setting its height to 0. It's z-index was already larger than that of the canvas.

rollover over image, different image appears below

I'm trying to make a grid of images that once you hover over one, it's webpage title appears below it, as well as the other images around it changing in opacity.
I have managed to create the opacity mouseover effect I want, but now I'm having trouble making the page heading images appear as you hover over the corresponding image. I hope that makes sense
Hope someone can help. Here is my code
HTML:
<div style="position: relative; left: 140px; top: 0px;">
<img src="window.jpg" style="position: relative; top: 0; left: 0;"/>
<div id="windowimages">
<a class="image-one"></a><a href="https://example-site.com/music/">
<img src="pic1.jpg/>
<a class="image-two"></a><a href="https://example-site.com/dance/">
<img
src="pic2.jgp"/>
<a class="image-three"></a><a href="https://example-site.com/art/">
<img
src="pic3.jpg" />
<a class="image-four"></a><a href="https://example-site.com/aboutus/">
<img
src="pic4.jpg"/>
</div>
CSS:
body {
}
#windowimages {
position: absolute;
left: 3px;
top: 4px;
font-size: 0;
width: 198px;
margin: 0 auto;
padding:1px;
overflow:hidden
}
#windowimages img {
width:90px;
height:90px;
margin: 3px;
cursor:pointer;
-webkit-transition:opacity 0.26s ease-out;
-moz-transition:opacity 0.26s ease-out;
-ms-transition:opacity 0.26s ease-out;
-o-transition:opacity 0.26s ease-out;
transition:opacity 2s ease-in-out;
}
#windowimages:hover img {
opacity:0.55;
}
#windowimages:hover img:hover {
opacity:1;
}
If I understood you correctly, it seems like what you want to do is add a title to each image on hover.
Check out this example I wrote: http://jsfiddle.net/arthurcamara/chbsL3pq/
The key part to adding the title was .image:hover:after as you can see above and in the code below:
.grid:hover .image:hover:after {
display: block;
position: absolute;
top: 5px;
width: 90px;
padding: 5px;
content: attr(data-title);
text-align: center;
background-color: #333;
color: #fff;
}
I changed your markup a bit as well to make it more semantic. Check out the example and let me know if that helped :)

Resources