Please, could someone help me accomplish the letter spinning effect on hover on this site? I managed to spin letters individually, but I'd like the whole word to flip with some delay among letters.
I've mostly followed this video. My code looks like this:
{/* html */}
<h1 className={styles.title}>
<div className={styles.letter_container}>
<span className={styles.letter}>s</span>
<span className={styles.letter}>o</span>
<span className={styles.letter}>n</span>
<span className={styles.letter}>g</span>
</div>
<div className={styles.letter_container}>
<span className={styles.letter}>o</span>
<span className={styles.letter}>f</span>
</div>
<div className={styles.letter_container}>
<span className={styles.letter}>t</span>
<span className={styles.letter}>h</span>
<span className={styles.letter}>e</span>
</div>
<div className={styles.letter_container}>
<span className={styles.letter}>d</span>
<span className={styles.letter}>a</span>
<span className={styles.letter}>y</span>
</div>
</h1>
/* css */
.letter_container {
display: flex;
flex-direction: row;
}
.letter {
cursor: pointer;
font-size: 4rem;
}
.letter_container span:hover {
animation: spin 1s infinite;
}
#keyframes spin {
from {
transform: rotateY(0deg);
}
to {
transform: rotateX(360deg);
}
}
Thank you in advance.
I'm not too sure, but if you'd like to spin the letters individually with delays between them like in the site, you could just add classes to the letters and make the whole animation start if they hover over the word.
.letter-1 {
transition-delay: 0.1s;
}
.letter-2 {
transition-delay: 0.1s;
}
or just add delays in-line style="--delay: 0.1s;" which is what they used in the website. I haven't looked into it too much so try inspecting the website's elements.
Extra CSS animation libraries if you still need them: Animate.css, Animista
Related
I have an animation and I have applied it to one of the html element just fine, but then when I applied the same animation on hover to another element(img) it just keep on flickering.
My CSS
.logo-box {
position: absolute;
top: 40px;
left: 40px;
}
.logo {
height: 35px;
}
.logo-box:hover {
animation: moveInRight 1s ease-in;
}
#keyframes moveInRight {
0% {
opacity: 0;
transform: translateX(100px);
}
80% {
transform: translateX(-10px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
.logo-box is absolute to the .header class
My HTML body
<body>
<header class="header">
<div class="logo-box">
<img class="logo" src="img/logo-white.png" alt="logo" />
</div>
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">Outdoors</span>
<span class="heading-primary-sub">is where life happends</span>
</h1>
</div>
</header>
</body>
Can anybody help me out fixing this...
Add a delay to the start of the animation.
.logo-box:hover {
animation: moveInRight 1s ease-in 0.5s;
/*the 0.5s is the delay*/
}
Explanation if you want to know whats going on:
This is a well known problem that is actually related to UX. The flicker problem is because of the opacity. As soon as a :hover occurs (event triggered) the opacity goes to zero. Now as you take your pointer to the image, multiple hover events are triggered due to micro movements of pointer. One hover event ends and second is triggered. CSS stops animating as soon as hover is ended and opacity gets to 100% and the second hover event causes it to go to 0 right away which is the flicker. If you add some delay then the mouse would get stable and then the animation will be played.
CSS, yet, isn't offering any way to complete the animation once hover is triggered i.e. no matter if the pointer is no more on the element, animation must be completed.
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.
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
I want to make a certain class, in this example "wrapper" have its background animate in when the page loads. I want them to appear staggered, so the first one animates in, then 1 second later the second, then one second later the third. The problem is, these are not and cannot be siblings. Because they are not siblings, I don't think you can use nth-of-type to accomplish this. Is there any other selector that I could use in my css to replace nth-of-type that would work? Fiddle: https://jsfiddle.net/q2drLsee/1/
CSS
#keyframes animateBackground {
100% { background-color: red; }
}
body {
background-color: white;
}
.wrapper {
animation: animateBackground 1s forwards;
display: inline-block;
padding: 0.1em;
&:nth-of-type(1) {
animation-delay: 1s;
}
&:nth-of-type(2) {
animation-delay: 2s;
}
&:nth-of-type(3) {
animation-delay: 3s;
}
}
HTML
<div>
Some text <span class="wrapper">some more text</span> and text after
</div>
<div>
Some text <span class="wrapper">some more text</span> and text after
</div>
<span class="wrapper">Some other text</span>
For a CSS only solution, the best I can think of is to target each .wrapper element individually. I don't see any way around this given the delay requirement and the variation in markup. You'll have to use nth-child and/or nth-of-type to target similarly structured markup. You also have to be sure of the order/placement of each .wrapper element. Any changes to the markup would require you to update the CSS which makes this solution very inflexible but so are the requirements. Not to mention that you'll likely be writing some crazy selectors.
The jQuery solution by Itay Ganor seems to be your best bet when it comes to flexibility and simplicity.
#keyframes animateBackground {
100% {
background-color: red;
}
}
body {
background-color: white;
}
.wrapper {
animation: animateBackground 1s forwards;
display: inline-block;
padding: 0.1em;
}
div:nth-of-type( 1 ) .wrapper {
animation-delay: 1s;
}
div:nth-of-type( 2 ) .wrapper {
animation-delay: 2s;
}
body > span.wrapper:nth-of-type( 1 ) {
animation-delay: 3s;
}
/* or */
/*
body > span.wrapper:nth-child( 3 ) {
animation-delay: 3s;
}
*/
<div>
Some text <span class="wrapper">some more text</span> and text after
</div>
<div>
Some text <span class="wrapper">some more text</span> and text after
</div>
<span class="wrapper">Some other text</span>
I would use jQuery or JavaScript, it'll make your life much easier.
I used jQuery for this example,
JSFiddle.
var delay = 1;
$(".wrapper").each(function() {
$(this).css('animation-delay', delay + 's');
delay++;
});
#keyframes animateBackground {
100% {
background-color: red;
}
}
body {
background-color: white;
}
.wrapper {
animation: animateBackground 1s forwards;
display: inline-block;
padding: 0.1em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
Some text <span class="wrapper">some more text</span> and text after
</div>
<div>
Some text <span class="wrapper">some more text</span> and text after
</div>
<span class="wrapper">Some other text</span>
If your content allows, you could add a second class specific to each wrapper:
body {
background-color: white;
}
.wrapper {
animation: animateBackground 1s forwards;
display: inline-block;
padding: 0.1em;
&.first {
animation-delay: 1s;
}
&.second {
animation-delay: 2s;
}
&.third {
animation-delay: 3s;
}
}
<div>
Some text <span class="wrapper first">some more text</span> and text after
</div>
<div>
Some text <span class="wrapper second">some more text</span> and text after
</div>
<span class="wrapper third">Some other text</span>
See the fiddle
I'm trying to create an overlay that says: 'Waiting...', but I want the ellipses to be animated. So the text would actually go from:-
'Waiting' -> 'Waiting.' -> 'Waiting..' -> 'Waiting...' -> 'Waiting' ->
However, when the ellipses count changes it's pushing the 'Waiting' to the left since the content is centered in its container.
HTML:
<div style='text-align: center'>
<span>Waiting</span>
<span id='ellipses'></span>
</div>
Javascript:
var ellipses = 0;
setInterval(function () {
$('#ellipses').text('.'.repeat(ellipses))
ellipses = (ellipses + 1) % 4;
}, 400)
Any good way to handle this ?, Easy to do with some magic numbers or manual calculation of what 'center' is + a fixed position, but I'd like to have a clean css solution if possible..
Using pure CSS, try this Fiddle,
.ellipses1 {
-webkit-animation: elipses 1.3s infinite;
-webkit-animation-delay: 0.0s;
}
.ellipses2 {
-webkit-animation: elipses 1.3s infinite;
-webkit-animation-delay: 0.2s;
}
.ellipses3 {
-webkit-animation: elipses 1.3s infinite;
-webkit-animation-delay: 0.3s;
}
#-webkit-keyframes elipses {
0% { opacity: 0; }
50% { opacity: 0; }
100% { opacity: 1; }
}
Try adding the following to your style:
#ellipses{
position:absolute;
}
Place the ellipsis inside an after pseudo element and declare its position as absolute. I created a fiddler to demonstrate the behavior. The ellipsis depends on your mouse pointer hovering over the second (middle) line for demonstration purpose: http://jsfiddle.net/f9eutj40/
HTML:
<div>
<span>
The first line
</span>
</br>
<span class="ellipsis">
The second line
</span>
</br>
<span>
The third line
</span>
</div>
CSS:
div {
text-align: center;
background-color: green;
}
span {
color: cyan;
}
span.ellipsis:hover:after {
color: cyan;
content: ".....";
position: absolute;
}
This way you don't even have to make a modification to the text itself (and clean it up afterwards again...). You just modify the styling of the text. This is done in a static manner in the demo above using the content: rule, but nothing speaks against doing that dynamic.