Hover Animation won't disappear when not hovering - html

I have a div I've animated on hover. However when I am not hovering the div won't disappear
This is what the entire thing looks like in action: http://jsfiddle.net/Vbxtc/
This is the html:
<nav>
<div id="controls">
<button id="playButton">Play</button>
<div id="defaultBar">
<div id="progressBar"></div>
</div>
<button id="vol" onclick="level()">Vol</button>
<button id="mute">Mute</button>
<button id="full" onclick="toggleFullScreen()">Full</button>
</div>
<div id="playlist" class="animated fadeInRight">
<div>cats</div>
<div>cats</div>
<div>cats</div>
</div>
</nav>
This is the CSS i've made:
#playlist{
position:absolute;
display:block;
border:1px solid red;
height: 82%;
width: 25%;
top: 20px;
right: 0px;
z-index: 2;
float:right;
padding: 0px;
margin: 0px;
color:white;
background-color:#999999;
opacity: 0;
}
#playlist:hover {
opacity: 1;
}
This is the animation im trying
.animated:hover {
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-ms-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
}
.fadeInRight {
-webkit-animation-name: fadeInRight;
-moz-animation-name: fadeInRight;
-o-animation-name: fadeInRight;
animation-name: fadeInRight;
}
#-webkit-keyframes fadeOutRight {
0% {
opacity: 1;
-webkit-transform: translateX(0);
}
100% {
opacity: 0;
-webkit-transform: translateX(20px);
}
}
#-webkit-keyframes fadeInRight {
0% {
opacity: 0;
-webkit-transform: translateX(20px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}

I noticed that when you time the mouse over exactly right (hover for about 1 second and move mouse up top), it DOES fade out nicely.
The other thing is, if you add the class fadeOutRight as follows:
<div id="playlist" class="animated fadeInRight fadeOutRight">
It fades out too quickly.
I know I didn't help much but the answer lies in the timing.
Also, if you had the fadeOutRight class on, for example, the sidebar, it works nicely!
<aside id="sidebar" class="fadeOutRight">
Perhaps, put the class of fadeOutRight on everything EXCEPT the fadeInRight div.

It's not a good idea to play with an element position in the hover state.
Even if you get to program it right (that is not easy), most of the time the user won't understand what's happening.
You can get flickering scenarios where, without the user moving the cursor, your div leaves the cursor position, canceling the hover, the div re-entering the cursor, the hover triggering , and so on.
I would recomend to trigger the hover on another div that covers the full area where the moving div will be.

Related

How to add animation to HTML/CSS box, when website loads box will load with animation?

I'm making a website using online Wix templates but the specific template didn't have all the things I needed so then I had to learn a little HTML/CSS. (I'm pretty new to it)
I've written the code below which shows a list of text (Company names) by sliding upwards. Once the user hovers the mouse on the text, the slider stops (onmouseover) and when the user moves the mouse pointer away from it the slider goes back to the same motion (onmouseout).
Link to some code: https://www.codepile.net/pile/WAJX9nrE
Okay so my questions are:
How can I animate this code so that when the webpage first loads this box will load in with some sort of animation?
And also instead of Company names, how can I add hyperlinks to the dedicated company's website?
To do this, add an animation for the element on page load through CSS. In the following example, this animation is called move-up which will run for 1 second. Additionally, to make a marquee, add an additional animation that loops. This is called slide in the following snippet which repeats every 16 seconds. The HTML of the companies will need to be duplicated to provide seamless looping. Finally, use a transition and the CSS :hover property to pause the animations when the mouse is over the card container. Here is a demo.
body {
overflow-y: hidden;
}
.card {
width: 200px;
height: 100px;
border-radius: 5px;
box-shadow: 0 5px 10px #888888;
padding: 10px;
margin: 20px;
display: inline-block;
/* Adds animation that runs on load */
animation-name: move-up;
animation-duration: 1s;
/* Adds transition */
transition: 0.3s;
/* Safari versions 8 and older */
-webkit-animation-name: move-up;
-webkit-animation-duration: 0.3s;
-webkit-transition: 0.5s;
}
/* Styles the container the card is in */
.card-container {
width: 100%;
overflow-y: show;
white-space: nowrap;
animation-name: slide;
animation-duration: 16s;
animation-iteration-count: infinite;
animation-timing-function: linear;
/* More Safari compatibility... */
-webkit-animation-name: slide;
-webkit-animation-duration: 16s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}
/* Plays transition on hover */
.card:hover {
transform: scale(1.1);
}
.card-container:hover {
animation-play-state: paused;
}
/* Defines animation on load */
#keyframes move-up {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Sliding animation */
#keyframes slide {
from {
transform: translateX(0);
}
to {
transform: translateX(-1320px);
}
}
/* Safari versions 8 and older */
#-webkit-keyframes move-up {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
#-webkit-#keyframes slide {
from {
transform: translateX(0);
}
to {
transform: translateX(-1320px);
}
}
<body>
<div class="card-container">
<div class="card">Company 1</div>
<div class="card">Company 2</div>
<div class="card">Company 3</div>
<div class="card">Company 4</div>
<div class="card">Company 5</div>
<!-- Duplicate cards are neccecary so that there is seemless looping. You may need even more if the cards do not fill the entire width of the page. -->
<div class="card">Company 1</div>
<div class="card">Company 2</div>
<div class="card">Company 3</div>
<div class="card">Company 4</div>
<div class="card">Company 5</div>
</div>
</body>
The link you provided is not working please repair the link.

How to fade html element out and the fade new element in it's place

I have a number of questions:
<div id='q1'>question...</div>
<div id='q2'>question...</div>
<div id='q3'>question...</div>
etc...
Only one question div should be visible at any time.
I want each question to fade out and the new question fade in exactly where the previous question was.
I am using this CSS for the fade transitions:
.fade-out {
opacity: 0;
animation-name: fadeOutOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
}
.fade-in {
opacity: 1;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 2s;
transition-delay: 4s;
}
#keyframes fadeInOpacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadeOutOpacity {
0% {
opacity:1;
}
100% {
opacity:0;
}
}
But when the second question has the fade-in css class applied, it makes the first question jump up before it's faded out.
Ideally, I'd like the first question to fade out and the become display: none;
But I am struggling to get it to work.
Questions
How can I get the first question to 'fade-out' and the second 'fade-in' in it's place?
N.B I'd rather a pure CSS solution than a Jquery solution if possible...
Like in most pure CSS solutions you might want to utilize input elements. Here I am using radio types with labels inside to reach the next question.
As you are only changing opacity you might want to use a transition instead of an animation. I am using the shorthand here which can be expanded like this:
transition: property-name duration easing delay;
Here is a working example:
/* wrapper to hold absolute positioned children */
.wrapper {
position: relative;
}
/* hide actual radio buttons */
.wrapper input {
display: none
}
.question {
/* float above each other */
position: absolute;
/* transparency by default */
opacity: 0;
/* fade out without delay */
transition: opacity 1s ease-out;
}
input:checked + .question {
/* always put current question first */
z-index: 1;
/* fade in with delay */
opacity: 1;
transition: opacity 2s ease-in 1s;
}
<div class="wrapper">
<input id="question-1" type="radio" name="question" checked>
<div class="question">
<p>Question 1</p>
<label for="question-2">next</label>
</div>
<input id="question-2" type="radio" name="question">
<div class="question">
<p>Question 2</p>
<label for="question-3">next</label>
</div>
<input id="question-3" type="radio" name="question">
<div class="question">
<p>Question 3</p>
<label for="question-1">start over</label>
</div>
</div>
You can do it easily without needing an animation Instead you only need transition.
Run this code snippet example:
function doNext() {
let el = document.querySelector('.questions [showing]');
el.removeAttribute('showing');
let temp = el.nextElementSibling;
if (temp === null) {
temp = el.parentElement.firstElementChild;
}
temp.setAttribute('showing', '');
}
const btn = document.querySelector('#next');
btn.addEventListener('click', doNext);
.questions {
height: 60px;
position: relative;
}
.fader {
left: 0;
opacity: 0;
position: absolute;
top: 0;
transition: all 1s ease;
}
.fader[showing] {
opacity: 1;
transition: all 1s ease 0.75s;
}
<div class="questions">
<div id='q1' class="fader" showing>question...1</div>
<div id='q2' class="fader">question...2</div>
<div id='q3' class="fader">question...3</div>
<div id='q4' class="fader">question...4</div>
</div>
<button id="next">Next</button>
When the attribute showing is removed then the opacity of the question goes from 1 to 0 over 1 seconds. When the attribute showing is added then the element waits for 0.75 seconds and then changes opacity from 0 to 1 over 1 seconds.
The JavaScript I have added simple allows the changing of which element has the attribute showing. Your code would need to do something similar to change which question is showing.
I set the position of each question to absolute with top set to 0 so that all questions show in the same place. BUT doing this requires that you know that maximum size of your questions so the container can be set to the correct height.
Try this sample:
.fade-out {
opacity: 0;
animation-name: fadeOutOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 2s;
height: 0;
width: 0;
}
.fade-in {
opacity: 1;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 4s;
animation-delay: 0s;
}
#keyframes fadeInOpacity {
0% {
opacity: 0;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadeOutOpacity {
0% {
opacity: 1;
height: auto;
width: auto;
}
100% {
opacity: 0;
}
}
<div id='q1' class="fade-out">question...1</div>
<div id='q2' class="fade-in">question...2</div>

Transform not working properly on anchor

I am trying to animate a button making it translate a little bit to the right for a specific time, but somehow the transition never happens.
#keyframes moveXpath {
0% {
transform: translateX(-10px);
}
100% {
transform: translateX(100px);
}
}
.btn-animate {
animation-name: moveXpath;
animation-duration: 10s;
}
<body>
<div class="container">
<h1>button animation</h1>
<div class="buttons">
rotating button
</div>
</div>
</body>
lost some time and can't figure out what is wrong any help?
Anchor are inline elements transform does not work on these type of elements.
Add a different display (block or inline-block) to your anchor
.btn-animate {
animation-name: moveXpath;
animation-duration: 10s;
display: inline-block;
}
Source: w3.org

css animation-name property does not allow transform property

I have the library animate.css loaded on my website and I animate an arrow moving onto the page using "fadeInLeftBig"
My html:
<div class="swipe-button b-left animated fadeInLeftBig"></div>
My css:
.swipe-button.b-left {
left: 10px;
background-image: url(/images/left-arrow.png);
}
.swipe-button:hover {
transform: rotate(90deg) !important;
}
Animate.css
.fadeInLeftBig {
animation-name: fadeInLeftBig;
}
.animated {
animation-duration: 1s;
animation-fill-mode: both;
}
#keyframes fadeInLeftBig {
0% {
opacity: 0;
transform: translateX(-2000px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
The transform: rotate(90deg) does not work on hover as long as animation-name: fadeInLeftBig is set on the element. But works if you unceck or comment it out.
I can see now there are two transform properties on the element, but Why does setting the animation-name property override the transform property with an !important flag from taking effect?
As vals stated earlier..an animation overrides the static properties. For what you're trying to achieve, you're best bet is to wrap your swipe-button class with a new fadeInLeftBig div:
<div class="fadeInLeftBig animated">
<div class="swipe-button b-left animated"></div>
</div>
Then use keyframe animations on both divs. This separates your animations so that your "fade in" doesn't start over once you unhover your swipe-button. Here's a working fiddle. https://jsfiddle.net/kj4v36ye/2/ Let me know if you're trying to achieve something else and I can easily modify it.
First at you code your don't close '}' in .fadeInLeftBig.
look at this fiddle:
<div class="swipe-button b-left animated fadeInLeftBig"></div>
and css
.swipe-button.b-left {
left: 10px;
background-color: blue;
width: 50px;
height: 50px;
}
.swipe-button:hover {
transform: rotate(45deg);
}
.fadeInLeftBig {
animation-name: fadeInLeftBig;
}
.animated {
animation-duration: 1s;
animation-fill-mode: both;
}
https://jsfiddle.net/kj4v36ye/

Cannot get CSS carousel slides img or text within to be clickable links

I have a CSS carousel that is working great thanks to a great coder on here, but as I am finishing up my project, I cannot make the images or text clickable in the slides. I have wrapped around the img, I have connect it to the text, and I cannot click anything, it just slides on its merry way. Below is the code:
.colorDissolve {
position: relative;
overflow: hidden;
width: 287px;
height: 430px;
background: #000000;
}
.colorDissolve .item {
position: absolute;
left: 0;
right: 0;
opacity: 0;
-webkit-animation: colorDissolve 24s linear infinite;
-moz-animation: colorDissolve 24s linear infinite;
-ms-animation: colorDissolve 24s linear infinite;
animation: colorDissolve 24s linear infinite;
}
.colorDissolve .item:nth-child(2) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
}
.colorDissolve .item:nth-child(3) {
-webkit-animation-delay: 12s;
-moz-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
}
.colorDissolve .item:nth-child(4) {
-webkit-animation-delay: 18s;
-moz-animation-delay: 18s;
-ms-animation-delay: 18s;
animation-delay: 18s;
}
.stars{
height: 220px;
background-color: rgba(11, 11, 44, 0.6);
position: absolute;
margin-left: 120px;
margin-top: -135px;
top:200px;
bottom:200px;
right:100px;
left:220px;
bottom: 143px;
color: #8df4fb;
padding-left: 20px;
padding-right: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
.space{
position:absolute;
top:100px;
bottom:100px;
left:390px;
color:#c30;
font-size:.9em;
padding:0.5em;
position:absolute;
right:10px;
left:10px;
text-align:right;
color:#fff;
background-color:rgba(0,0,0,0.75);
}
#-webkit-keyframes colorDissolve {
0%, 25%, 100% { opacity: 0; }
4.17%, 20.84% { opacity: 1;}
}
#-moz-keyframes colorDissolve {
0%, 25%, 100% { opacity: 0; }
4.17%, 20.84% { opacity: 1;}
}
#-ms-keyframes colorDissolve {
0%, 25%, 100% { opacity: 0; }
4.17%, 20.84% { opacity: 1;}
}
#keyframes colorDissolve {
0%, 25%, 100% { opacity: 0; }
4.17%, 20.84% { opacity: 1;}
}
<div class="carousel colorDissolve">
<div class="item">
<a href="star.html">
<img src="images/stars.gif" />
</a>
<span class="stars">
<h2>Science</h2>
<p>TEXT</p>
<h2>The new Style of Space</h2>
</span>
</div>
<div class="item">
<a href="space.html">
<img src="images/galaxy.gif" />
</a>
<span class="space">
<h2>Science</h2>
<p>TEXT</p>
<h2>The new Style of Space</h2>
</span>
</div>
<div class="item">
<a href="moon.html">
<img src="images/moons.gif" />
</a>
<span class="space">
<h2>Science</h2>
<p>TEXT</p>
<h2>The new Style of Space</h2>
</span>
</div>
<div class="item">
<a href="nebula.html">
<img src="images/nebulae.gif" />
</a>
<span class="space">
<h2>Science</h2>
<p>TEXT</p>
<h2>The new Style of Space</h2>
</span>
</div>
</div>
I also have put the link code by the text, around the headers, and there is no link option. I tried the z-index, and it still does not work, and I do not think it should go higher than my nav links, right? Are maybe my nav links somehow messing up my img links? I am not sure what I am missing, I have put the in the span sections as well, but I cannot get it to work. I also have links to facebook and twitter, but they do not interfere with anything. I am just a bit stuck here. I just cannot solve this problem.
EDIT: Ok, so I now have the links working for text, what I was able to do was use the z-index to put the linked text on top of the div layer and I can now click on those links as they are present. I obviously made the z-index ratio higher than the links in the footer, and it works great. The only issue I still have is getting the whole slide itself or just the picture itself to link or be clickable in its own right, as it pulls from another div layer, basically using my ul a attribute when I hover over the picture, which is not what I want it to do.
That's weird, for me it works correctly (only you forgot the first < tags for your item divs)
If you want a clickable entire div => change <div class="item"> to <a class="item">
If you want a clickable image inside div => wrap a tags around the img
If you want a clickable text inside div => wrap a tags around <span class="space">
If it doesn't work, you've probably made a typing mistake, because in this test:
http://jsbin.com/apuwal/2/edit , wherever I wrap the anchor tags, it works.
EDIT: Ah I got you now. I re-tested the code with a function alerting the href of a link when clicking on it. After some searching, it turned out, you have to scrap the position: absolute; from your classes .space (twice!) & .item. http://jsbin.com/apuwal/7/edit
This is because absolute positioning ignores the presence of other elements, and so your elements will all stack up at the same position and only one link will be clickable. If you wish to keep the position of your items absolute, you will either have to:
set different margins for your elements so they don't overlap
Use keyframes (dunno if this is possible, never tried) to change the z-index of the item with opacity > 0.5 or so
Set your items to display: none; when they finish fading out. (through Javascript/ jQuery)
Give the hidden elements a different margin when they fade out.
I know CSS sliders/faders are pretty sophisticated now, but the way I see it right now, the easiest solution would still be javascript