Can't stop animation fro cycling - css

I have three images in a row. I want to enlarge the one that the mouse is over until the mouse is moved off of it. This sort of works in my jsfiddle but, as you can see, the animation doesn't stop after enlarging. The other threads on this problem say to set the iteration count and forwards options, which I've done. The only other solution I could find was to use javascript to control it. Is there a way to do this with just css? Here's my code:
<style>
#set2 {margin-left:40px; display:inline-block}
#set2:hover {
-webkit-animation: enlarge 5s;
animation: enlarge 5s;
animation-fill-mode: forwards;
animation-iteration-count: 1;
}
#-webkit-keyframes enlarge {
25% {
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
}
</style>
<div class="banner_set">
<ul class="nav">
<li id="set2" class="nav-items"><img src="example1.jpg"></li>
<li id="set2" class="nav-items"><img src="example2.jpg"></li>
<li id="set2" class="nav-items"><img src="example3.jpg"></li>
</ul>
</div>

Your keyframe set at 25% means your element will be scaled 1/4 of the way through the animation, then not scaled at the end. If you just want a smooth scale up and that's all, use 100% (and I would suggest, reduce the duration!).
I updated your fiddle. The weird image styling is so we can see your images.
#set2 {margin-left:40px; display:inline-block}
#set2:hover {
-webkit-animation: enlarge 2s;
animation: enlarge 2s 1 forwards;
}
#-webkit-keyframes enlarge {
100% {
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
}
img {
min-height: 30px;
min-width: 30px;
border: 3px solid red;
}
<div class="banner_set">
<ul class="nav">
<li id="set2" class="nav-items"><img src="example1.jpg"></li>
<li id="set2" class="nav-items"><img src="example2.jpg"></li>
<li id="set2" class="nav-items"><img src="example3.jpg"></li>
</ul>
</div>

Is there a specific reason you're using the animation approach rather than a transition?
Since the desired behavior is to toggle between two animated states, perhaps the transition is an easier way to approach it.
Using your example code:
.nav {margin:0; padding-top:5px;overflow:hidden}
.nav-items {border:1px solid black}
.nav-items {margin-left:0px; display:inline-block; overflow: hidden;}
.nav-items:hover img {
box-shadow: 0px 0px 150px #000000;
z-index: 2;
-webkit-transition: all 500ms ease-in;
-webkit-transform: scale(2.1);
-ms-transition: all 500ms ease-in;
-ms-transform: scale(2.1);
-moz-transition: all 500ms ease-in;
-moz-transform: scale(2.1);
transition: all 500ms ease-in;
transform: scale(2.1);
}
.nav-items img {
-webkit-transition: all 200ms ease-in;
-webkit-transform: scale(1);
-ms-transition: all 200ms ease-in;
-ms-transform: scale(1);
-moz-transition: all 200ms ease-in;
-moz-transform: scale(1);
transition: all 200ms ease-in;
transform: scale(1);
}
<div class="banner_set">
<ul class="nav">
<li id="0" class="nav-items small_0"><img src="http://placehold.it/200x200"></li>
<li id="1" class="nav-items small_1"><img src="http://placehold.it/200x200"></li>
<li id="2" class="nav-items small_2"><img src="http://placehold.it/200x200"></li>
</ul>
</div>

Related

Image transform on hover HTML and JavaScript only

The transform seems to work ok, but I've noticed that on the initial hover or touch the image doesn't open properly. After the initial touch or hover everything seems to function great. Thanks in advance for any assistance with what I hope is a simple fix.
body {
background: #000000;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.hoverChange:hover {
content: url("https://i.postimg.cc/CL7mTV8p/monster.png");
width: 100%;
-moz-transform: scale(2.2) rotatez(-5deg);
-webkit-transform: scale(2.2) rotatez(-5deg);
-o-transform: scale(2.2) rotatez(-5deg);
-ms-transform: scale(2.2) rotatez(-5deg);
transform: scale(2.2) rotatez(-5deg);
cursor: crosshair;
-webkit-transition: .7s;
-moz-transition: .7s;
-o-transition: .7s;
-ms-transition: .7s;
transition: .7s;
translate: -100px -100px;
/* When the animation is finished, start again */
animation-iteration-count: infinite;
}
.avatar {
transform: translatey(0px);
animation: float 5s ease-in-out infinite;
}
.avatar {
transform: translatey(0px);
animation: float 5s ease-in-out infinite;
}
#keyframes float {
0% {
transform: translatey(0px);
}
50% {
transform: translatey(-15px);
}
100% {
transform: translatey(0px);
}
}
<div class="col-sm-8 col-md-6 monster mb-5" data-animation="slideInLeft"
style="background-image: url(https://i.postimg.cc/NjPDF7bN/photo-1620207418302-439b387441b0.jpg)" ;>
<div class="px-5 hoverChange px-sm-0"><img
src="https://i.postimg.cc/vmk0qLV1/Web-Development-Promotion-Instagram-Post.png"
class="smallBorder avatar" width="100%"></img></div>
</div>
The only think I can think of is that the images are taking up to 1s to get. Using the web tools on your browser it's possible to see the network timings for each image. https://i.postimg.cc/vmk0qLV1/Web-Development-Promotion-Instagram-Post.png" took 1.3s to get and monster.png took about 1s to get.
The network request for monster.png only occurs at the hover event so it may be that it's just taking time to get the asset so you're not seeing the effect straight away.
A method for avoiding this behaviour has already been discussed here

Smooth effect CSS animation for hover out

I'm trying to get a smooth "hover out" animation when you stop hovering the object. The font-awesome icon is rotating when you hover the whole button.
I'm using it:
#keyframes roll {
from {
transform: rotateY(0);
}
to {
transform: rotateY(360deg);
}
}
.p-navEl a:first-child:hover::before {
animation: roll .5s linear infinite;
}
HTML for the first button of the nav bar
<ul class="p-nav-list js-offCanvasNavSource">
<li>
<div class="p-navEl is-selected" data-has-children="true">
Forums
<a data-xf-key="1" data-xf-click="menu" data-menu-pos-ref="< .p-navEl" data-arrow-pos-ref="< .p-navEl" class="p-navEl-splitTrigger" role="button" tabindex="0" aria-label="Basculer en mode étendu" aria-expanded="false" aria-haspopup="true"></a>
<div class="menu menu--structural" data-menu="menu" aria-hidden="true">
<div class="menu-content">
Nouveaux messages
Trouver des discussions
Vos discussions
Discussions avec vos messages
Discussions sans réponse
<hr class="menu-separator">
Suivies
Discussions suivies
Forums suivis
<hr class="menu-separator">
Rechercher dans les forums
Marquer les forums comme lus
</div>
</div>
</div>
</li>
</ul>
PREVIEW
The bubble before "FORUMS" is rotating when you hover it. But I want the animation smooth when you stop hovering it
but when you don't hover the link anymore, the animation is brutaly stopped.
Any idea?
I can't share the original CSS since it's a userscript for a public/private website I'm not the owner!
Please do try transitions like below and let me know fiddle!.
HTML
<body bgcolor="#333">
<div class="display-center">
<span>Rotate</span>
</div>
</body>
Css
.display-center{
display:flex;
justify-content: center;
align-items: center;
height: 400px;
width: 100%;
background-color: white;
}
span {
background-color: gray;
padding: 10px;
border-radius: 8px;
color: #222;
text-align: center;
transition: 0.70s;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
display: block;
margin-right: auto;
margin-left: auto;
}
span:hover {
transition: 0.70s;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}

transition functions and their order of operation

I'm trying to understand how the transform property works with order of operation and its relevance to the transform duration.
Say I have some html
<div class="container">
<ul>
<li id="obj-1">Item 1</li>
<li id="obj-2">Item 2</li>
</ul>
</div>
The relevant css for container would be:
transition: all 6s ease 0s;
Now if I wanted to transform #obj-1, id write something like this:
#obj-1 {
// some styling
}
#obj-1:hover {
transform: scale(10) scale(2) scale(0.05);
}
How would the browser interpret this css? My initial thought would be that it would allocate each "function" (3) an allocated amount of time (6s/3fun = 2 sec per fun). It doesn't work that way so I wanted to know if someone might point out what it is that determines how long each function would run or if they are somehow altered before execution.
Your allocated amount of time for the animation actually depends on the transition-timing-function. Here you have given ease as a transition-timing-function. ease does not distribute time equally.
If you want your time equally distributed, you have to use transition-timing-function: linear for that.
See the example below you will see the difference.
More help on Transition CSS
.main div {
width: 100px;
height: 100px;
background: red;
margin-bottom: 8px;
}
.main:hover div {
transform: translateX(200px);
}
.one {
transition: all 1s ease;
}
.two {
transition: all 1s linear;
}
.three {
transition: all 1s ease-in;
}
<div class="main">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
And your answer to transform: scale(10) scale(2) scale(0.05);
It will take the highest scale value i.e. 10, So your element will take the scale(10) as the transform.
Note: If any scale contain 0 then scale(0) will take effect
But other than scale() all transform values translate, rotate works differently.
translateX(100px) translateX(100px) translateX(100px) will result translateX(300px)
rotate(45deg) rotate(45deg) will result rotate(90deg)
See the example below
div {
width: 100px;
height: 100px;
background: red;
margin: 0 auto 8px;
transition: all 1s linear;
}
div.one:hover {
transform: rotate(45deg) rotate(45deg);
}
div.two:hover {
transform: translateX(100px) translateX(100px);
}
div.three:hover {
transform: scale(2) scale(1);
}
div.four:hover {
transform: scale(0) scale(2);
}
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
And if you want to run these transfomm values in order I prefer to use
#keyframes CSS

Overlaying text on image not working

I have three images in a row. The images don't have text in them. That needs to be added with the code. I used the method described in posts here (using relative and absolute positions) and have it somewhat working. Here is the jsfiddle. There are two main problems.
First, the placement isn't consistent. If the window is resized, the text doesn't move with the image. On a smartphone, the text disappears completely.
Second, when the images are mousedover they expand. But if the mouse is moved over the text, the expanding stops. If I remove the z-index then the text disappears when the image is mousedover. I want to have the text always show but also to expand the image. My code is below. It is taken from the example here, except for the text overlay, which I added. Is it possible to add text to an image that changes and have it work as described?
<style>
.nav {margin:0; padding-top:5px;overflow:hidden}
.nav-items {border:1px solid black}
.nav-items {position:relative;margin-left:0px; display:inline-block; overflow: hidden;}
.nav-items:hover img {
box-shadow: 0px 0px 150px #000000;
z-index: 2;
-webkit-transition: all 500ms ease-in;
-webkit-transform: scale(2.1);
-ms-transition: all 500ms ease-in;
-ms-transform: scale(2.1);
-moz-transition: all 500ms ease-in;
-moz-transform: scale(2.1);
transition: all 500ms ease-in;
transform: scale(2.1);
}
.nav-items img {
-webkit-transition: all 200ms ease-in;
-webkit-transform: scale(1);
-ms-transition: all 200ms ease-in;
-ms-transform: scale(1);
-moz-transition: all 200ms ease-in;
-moz-transform: scale(1);
transition: all 200ms ease-in;
transform: scale(1);
}
#bannerText_0,
#bannerText_1,
#bannerText_2{
position:absolute;
font-size:20px;
line-height: 150%;
color:#fff;
top:60px;
background:transparent;
z-index:999;
}
#bannerText_0{left:10%;}
#bannerText_1{left:35%;}
#bannerText_2{left:60%;}
</style>
<div class="banner_set">
<ul class="nav">
<li id="0" class="nav-items"><img src="http://placehold.it/130x130"></li>
<div id="bannerText_0">Img 1</div>
<li id="1" class="nav-items"><img src="http://placehold.it/130x130"></li>
<div id="bannerText_1">Img 2</div>
<li id="2" class="nav-items"><img src="http://placehold.it/130x130"></li>
<div id="bannerText_2">Img 3</div>
</ul>
</div>
The main problem is that the structured your HTML incorrectly - you can't put <div>s in between the <li> elements in the <ul>.
As well as causing the broken layout, its also the reason the mouseover on the text affects the image doesn't work - the text isn't actually inside an nav-item element that has the hover effect.
You can solve all your problems by putting your div's inside the <li> elements!
Bonus Fix :), I've also fixed the space at the bottom under the image - just make the image display:block;.
Your Fiddle, updated with these changes: https://jsfiddle.net/pcpg7zww/2/
Working snippet:
.nav {margin:0; padding-top:5px;overflow:hidden}
.nav-items {border:1px solid black}
.nav-items {position:relative;margin-left:0px; display:inline-block; overflow: hidden;}
.nav-items:hover img {
box-shadow: 0px 0px 150px #000000;
z-index: 2;
-webkit-transition: all 500ms ease-in;
-webkit-transform: scale(2.1);
-ms-transition: all 500ms ease-in;
-ms-transform: scale(2.1);
-moz-transition: all 500ms ease-in;
-moz-transform: scale(2.1);
transition: all 500ms ease-in;
transform: scale(2.1);
}
.nav-items img {
-webkit-transition: all 200ms ease-in;
-webkit-transform: scale(1);
-ms-transition: all 200ms ease-in;
-ms-transform: scale(1);
-moz-transition: all 200ms ease-in;
-moz-transform: scale(1);
transition: all 200ms ease-in;
transform: scale(1);
display:block; /* this will remove the space at the bottom */
}
#bannerText_0,
#bannerText_1,
#bannerText_2{
position:absolute;
font-size:20px;
line-height: 150%;
color:#fff;
top:60px;
background:transparent;
z-index:999;
}
#bannerText_0{left:10%;}
#bannerText_1{left:35%;}
#bannerText_2{left:60%;}
<div class="banner_set">
<ul class="nav">
<li id="0" class="nav-items">
<a href="example.com">
<img src="http://placehold.it/130x130">
<div id="bannerText_0">Img 1</div>
</a>
</li>
<li id="1" class="nav-items">
<a href="example.com">
<img src="http://placehold.it/130x130">
<div id="bannerText_1">Img 2</div>
</a>
</li>
<li id="2" class="nav-items">
<a href="example.com">
<img src="http://placehold.it/130x130">
<div id="bannerText_2">Img 3</div>
</a>
</li>
</ul>
</div>

how to give transition differently with delay in transform properties scale, transform,rotate etc

this is not right way to do i know that and it's not working anymore it's only done for understand my problem.
div
{
transform: rotate(0deg) translate(0);
transition:rotate 0.2s linear, translate 0.3s linear 0.2s;
}
div:hover
{
transform: rotate(60deg) translate(40);
}
As per css3 standards its not possible to achieve the same which you have mentioned. Instead you can make something like this.
<div class="outer">
<div class="inner">
</div>
</div>
.outer
{
height:30px;
width:30px;
transform:translateX(0);
transition:transform 2s linear;
}
.inner{
width: inherit; height: inherit;
transform: rotate(0deg);
transition:transform 2s linear;
background:blue
}
.outer:hover
{
transform: translateX(140px);
}
.outer:hover .inner
{
transform: rotate(160deg);
}

Resources