How to create a CSS slide loop that is smoth - css

i need some help with a css slide loop,
Its working but the slide is not smooth, there is a jittering and there is a jump at the end the loop.
I kept changing the keyframe but i just cant find a way to make is smooth without jittering
So here's the code :
thats the container :
.container {
max-width: 1140px;
position: relative;
width: 100%;
margin: auto;
text-align : center ;
overflow : hidden;
}
// here the column where the images slides
.col-lg-3 {
animation: slide 15s linear infinite;
margin: 20px 5px ;
}
#keyframes slide {
0% {transform: translate(0)}
100% { transform: translateX(calc(-250px * 5))}
}

Pretty sure that there must be a better solution. But you need to ask better question i think.
I still don't know what do you need, but check this maybe it will help.
I create a box full of images and give that box a margin-left (comes from justify content: end inside parent container(main-container)) and cover it with another box (cover-container) which have a position:absolute on it. and have a higher z-index than main-container and same background-color with main-container.
In animation i gave
100% {
transform: translateX(-600%);
}
-600% because i have 5 images and when i give 5 width it acts like it is jumping as you said in your question but when giving 600% (5 + 1) it acts better like continious loop.
img{
display: block;
max-width: 100%;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body{
min-height: 100vh;
overflow: hidden;
position: relative;
margin:0;
}
.container {
max-width: 1200px;
display: grid;
place-content: center;
margin: 0 auto;
background-color: bisque;
height: 100vh;
}
.main-container{
display: flex;
overflow : hidden;
justify-content: end;
}
.cover-container {
position: absolute;
display: grid;
place-content: center;
height: 400px;
width: 900px;
z-index: 999;
margin-left: 300px;
background-color: bisque;
overflow: hidden;
}
.image-container{
position: relative;
display: flex;
width: 75%;
height: 400px;
}
img{
animation: slide 7.5s linear infinite;
}
#keyframes slide {
0% {
transform: translate(0);
}
100% {
transform: translateX(-600%);
}
}
<div class="container">
<div class="main-container">
<div class="cover-container"></div>
<div class="image-container">
<img src="https://source.unsplash.com/random/300x400" alt="" />
<img src="https://source.unsplash.com/random/300x400" alt="" />
<img src="https://source.unsplash.com/random/300x400" alt="" />
<img src="https://source.unsplash.com/random/300x400" alt="" />
<img src="https://source.unsplash.com/random/300x400" alt="" />
</div>
</div>
</div>

Related

Set an image inside CSS spinner and want it to resize it.image should be in static

I am working on an angular application and implemented spinner using CSS.
Now the spinner working as expected.
I have added a background image inside the CSS using background-image:url()
Here, the problem is image also rotate with the spinner.
Here is my CSS
#spinner {
-webkit-animation: frames 1s infinite linear;
animation: frames 1s infinite linear;
background: transparent;
border: .3vw solid #FFF;
border-radius: 100%;
border-top-color: #250463;
background-image:url("../../../../assets/images/svg/img.svg") ;
width: 5vw;
height: 5vw;
opacity: .6;
padding: 0;
position: absolute;
z-index: 999;
justify-content: center;
align-items: center;
}
#keyframes frames {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
.spinner-wrapper {
position: fixed;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.3);
z-index: 998;
}
html code
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
</div>
Experiment 1
added another style img
img {
max-width: 5vw;
position: absolute;
max-height: 5vw;
top: 0;
height: 5vw;
width: 5vw;
clip-path: circle(45% at 50% 49%);
}
i have updated my html code as well
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
<img src="">
</div>
Experiment 2
added background-attachment: fixed; inside spinner.Still the image is rotating
**Experiment 3 **
I made below changes.now its working
added new css
z-index: 8;
justify-content: center;
top:230px;
left: 575px;
.img {
position: absolute;
top: 0;
width: 42px;
height: 48px;
}
html changes
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
<img src="../../../../assets/images/svg/img.svg">
</div>
One draw back is here.if i change the screen size,spinner and image appears different position
how can i solve this
Now the image showing some where else in the UI.
how can i include image inside the spinner.
How can i stop spinning my image?
Can we set image size
This is my first experience on CSS.If anything wrong please correct me.

Is there a clear way of setting the context of a Z-index inside nested transformations

I am currently working on a project that has div with a background image sliding in using a transform: translate. This div has a z-index of zero while some other sibling elements have a higher z-index to ensure they are placed on top. This seems to work fine in my landscape version. However, as this use case only has a landscape version, I am also implementing a transform: rotate when in portrait mode to ensure landscape viewing. When viewing in portrait, the background image slides in above everything, then relocates to the back. Not breaking, but sloppy, as this should be rotated anyways. However, after deployment, I was informed that there have been two instances of the image never relocating to its 0 Z-index home and breaking the usage. I have looked at https://katydecorah.com/code/z-index-and-transform/ and z-index is canceled by setting transform(rotate) and am still not sure how to approach this.
The issue only seems to occur in Safari while applying the rotate.
Rough outline of HTML elements:
<div id="root">
<div class="App ">
<div class="mainView">
<div class="navBar"></div>
<div class="mainContent">
<div class="arrowWrapper">
<div class="arrow slideInItem"></div>
</div>
<div class="alphaView">
</div>
<div class="footerBar"></div>
</div>
</div>
</div>
Some of the relevant CSS:
.App {
text-align: center;
height: 100%;
width:100%;
}
.mainView{
height: 100%;
width: 100%;
background-color: #fff;
overflow:hidden;
position: relative;
transform-style: preserve-3d;
}
.navBar{
height: 79px;
width: 100%;
display:flex;
flex-direction: row;
align-items: center;
background-color: #fff;
}
.mainContent{
display:flex;
flex-direction:column;
justify-content:flex-end;
margin-top: 18px;
height:85.25%
}
.arrow{
position: absolute;
z-index: 0;
top: 0;
width: 100%;
height: 100%;
background-size: contain;
background-image: url("../images/Page_background_Arrow.png");
background-repeat: no-repeat;
}
.arrowWrapper{
transform-style: preserve-3d;
position: absolute;
z-index: 0;
top: 97px;
width: 100%;
height: 86%;
}
.alphaView{
display: flex;
height: 100%;
width: 100%;
overflow:hidden;
position: relative;
z-index: 10;
justify-content: space-around;
}
.footerBar{
z-index: 999;
position:fixed;
top:auto;
display:flex;
bottom:0;
height: 6.15%;
width:100%;
flex-direction:row;
align-items:center
}
/* portrait lock */
#media only screen and (min-width: 100px) and (orientation:
portrait) {
#root {
transform: rotate(-90deg);
transform-origin: left top;
height: 100vw;
width: 100vh;
overflow: hidden;
position: absolute;
top: 100%;
left: 0;
}
}
Thank you
Try setting a -1 index to the background image.
This is a very good article for z-index too What the heck, z-index??

css bubble chat slide up animation

I'm trying to create chat animation using CSS only. So far, I have tried creating this. My question is how to hide a bubble when it's not their time to show up?
#keyframes slide {
from {bottom: -20px}
to {bottom: 0px}
0% { opacity: 0; }
100% { opacity: 1; }
}
Also, I figured that this is not the best approach to create chat animation. I still haven't thought about how to hide the older bubble chat when the chat is getting longer. Does anyone know what's the best approach to create this animation but using CSS only?
The key idea is to use a flexbox container which flex-direction: column-reverse so the messages are always bottom-anchored. Doing so you need to insert the markup of the whole chat in reverse order.
The container has a ::before pseudoelement stacked on top with a gradient as a background, so, while the conversation is scrolling, the messages seem to disappear on the top area.
The animation on the messages can be done using a different animation-delay for each message and animation-fill-mode: forwards to keep the values of the last keyframe.
*, *::before {
box-sizing: border-box;
}
.chat {
display: flex;
flex-direction: column-reverse;
height: 12rem;
overflow: hidden;
border: 1px #ccc dashed;
font: .85rem/1.5 Arial;
color: #313131;
position: relative;
}
.chat::before {
content: "";
position: absolute;
z-index: 1;
top: 0;
height: 40%;
width: 100%;
background: linear-gradient(to bottom, white 20%, rgba(255, 255, 255, 0)) repeat-x;
}
.chat p {
margin: 0;
padding: 0;
}
.chat__content {
flex: 0 1 auto;
padding: 1rem;
margin: 0 0.5rem;
background: var(--bgcolor);
border-radius: var(--radius);
}
.chat__message {
width: 45%;
display: flex;
align-items: flex-end;
transform-origin: 0 100%;
padding-top: 0;
transform: scale(0);
max-height: 0;
overflow: hidden;
animation: message 0.15s ease-out 0s forwards;
animation-delay: var(--delay);
--bgcolor: #d8d8d8;
--radius: 8px 8px 8px 0;
}
.chat__message_B {
flex-direction: row-reverse;
text-align: right;
align-self: flex-end;
transform-origin: 100% 100%;
--bgcolor: #d2ecd4;
--radius: 8px 8px 0 8px;
}
.chat__message::before {
content: "";
flex: 0 0 40px;
aspect-ratio: 1/1;
background: var(--bgcolor);
border-radius: 50%;
}
#keyframes message {
0% {
max-height: 100vmax;
}
80% {
transform: scale(1.1);
}
100% {
transform: scale(1);
max-height: 100vmax;
overflow: visible;
padding-top: 1rem;
}
}
<section class="chat">
<div class="chat__message chat__message_B" style="--delay: 18s;">
<div class="chat__content">
<p>Thank you.</p>
</div>
</div>
<div class="chat__message chat__message_A" style="--delay: 13s;">
<div class="chat__content">
<p>Mr.Doe, your current balance is $19,606.76</p>
</div>
</div>
<div class="chat__message chat__message_A" style="--delay: 10s;">
<div class="chat__content">
<p>Sure, let me check...</p>
</div>
</div>
<div class="chat__message chat__message_B" style="--delay: 6s;">
<div class="chat__content">
<p>Hi jane, I'm John Doe. <br />
I need to know my current account balance</p>
</div>
</div>
<div class="chat__message chat__message_A" style="--delay: 1s;">
<div class="chat__content">
<p>Hello, my name is Jane.<br />
How can I help you?</p>
</div>
</div>
</section>

How can I create Responsive Flip Cards with Only CSS?

I'm using some CSS I found in the wild to make flip cards. I've made a few adjustments in an attempt to make them fluidly responsive. My attempt is here:
https://jsfiddle.net/u18rhf6q/
css:
.flip-card-wrapper {
width: 50%;
height: auto;
}
.flip-card {
background-color: transparent;
width: 100%;
height: 100%;
perspective: 1000px;
}
.flip-card img {
width: 100%;
height: auto;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-card-wrapper:hover .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-card-front {
color: black;
}
.flip-card-back {
background-color: #c1272d;
color: white;
transform: rotateY(180deg);
}
html
<div class="flip-card-wrapper" >
<div class="flip-card" >
<div class="flip-card-inner">
<div class="flip-card-front">
<img src="https://dummyimage.com/600x600/000/fff" alt="Avatar" >
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
</div>
What I hope to happen is if I adjust the width of flip-card-wrapper, the contents would expand relative to that width and the flip would continue. However, it only works if I also supply a height to flip-card-wrapper. Since the front and back are both absolute, I can't a height to bubble up. Any ideas?
One possibility for keeping your card height responsive might be to set a padding-bottom or padding-top on your flip-card-inner class. Since those heights are based on the parent's width when you use a percentage, padding-bottom: 100%; should create a perfect square. If you want to play around with the sizing, there's a good overview of aspect ratio boxes at https://css-tricks.com/aspect-ratio-boxes/.

Flexbox vertical content align with overflow in Internet Explorer

Edit: Everybody getting here trying to find a solution for IE's flexbox behavior with overflow have a look at this stackoverflow thread. Seems this is not going to be fixed. I was able to work around the issue, see answer below, but there might be cases (responsive height) where you can't.
I've got a problem with IE11 (surprise) that I don't know how to fix.
A child that overflows it's parent container should be centered horizontally and vertically when transitioned in size. I'm trying to do it with flexbox, but anything else that works would be fine as well.
When researching for IE flexbox alignment issues I just found a bug that applies when using min-height, the workarounds didn't help in this case.
Below is a simplified example of the problem. Watch in IE and you'll see the shape is starting it's animation from the top instead of the center. Every other browser will keep the shape centered.
Here's a fiddle to play around with: jsfiddle
Any idea would be appreciated :)
.container {
background-color: grey;
height: 150px;
width: 100%;
justify-content: center;
flex-direction: column;
display: flex;
overflow: hidden;
}
.child {
background-color: lightgrey;
height: 100%;
width: 100%;
flex: 1 0 auto;
align-self: center;
font-size: 5em;
animation: changesize 3s infinite;
}
svg {
width: 100%;
height: 100%;
}
.st0{fill:#00748A;}
.st1{fill:#D3D938;}
#keyframes changesize {
0% { width: 100%; height: 100%; }
50% { width: 500%; height: 500%; }
100% { width: 100%; height: 100%; }
}
<div class="container">
<div class="child">
<svg version="1.1" id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3000 3000"><circle class="st0" cx="1500" cy="1500" r="1401.2"/><circle class="st1" cx="1500" cy="1500" r="45.2"/>
</svg>
</div>
</div>
Because .container has a fixed height we can use absolute positioning to center .child.
.container {
background-color: grey;
height: 150px;
width: 100%;
position: relative;
overflow: hidden;
}
.child {
background-color: lightgrey;
height: 100%;
width: 100%;
left: -200%;
right: -200%;
top: -200%;
bottom: -200%;
margin: auto;
position: absolute;
font-size: 5em;
animation: changesize 3s infinite;
}
svg {
width: 100%;
height: 100%;
}
.st0 {
fill: #00748A;
}
.st1 {
fill: #D3D938;
}
#keyframes changesize {
0% {
width: 100%;
height: 100%;
}
50% {
width: 500%;
height: 500%;
}
100% {
width: 100%;
height: 100%;
}
}
<div class="container">
<div class="child">
<svg version="1.1" id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3000 3000"><circle class="st0" cx="1500" cy="1500" r="1401.2"/><circle class="st1" cx="1500" cy="1500" r="45.2"/>
</svg>
</div>
</div>

Resources