Last image slides too fast - html

It is a slide in a html using css.
However when it slides to the last image (the duration of the last image is too short), it carries on to the first too fast. All the rest of the images are fine.
Here is the html part:
<div id="slider" style="text-align: center">
<figure>
<img src="pics/img01.png">
<img src="pics/img02.png">
<img src="pics/img03.png">
<img src="pics/img04.png">
<img src="pics/img05.png">
</figure></div>
Here is the css part:
#keyframes slidy{
0%{left: 0%;}
20%{left: 0%;}
35%{left: -100%;}
45%{left: -150%;}
55%{left: -200%;}
65%{left: -250%;}
75%{left: -300%;}
95%{left: -350%;}
100%{left: -400%;}
}
body { margin: 100px left; }
div#slider { overflow: hidden; }
div#slider figure img { width: 20%; float: left; }
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}

Yeah, I fixed your slideshow issue. It runs very smoothly now Check the codepen here.
The main thing about CSS sliders you have to keep in mind is the width you have given & the way you slide your different slides within that given width. Its all about maintaining that balance between width & the time taken to complete that one cycle of covering the width.
In your case you had 5 images but have broken your #keyframes into too many levels(the levels depend on the width of each of your images).
I have included an image showing how it works & broken your #keyframes as shown below:
#keyframes slidy{
0%{left: 0%;}
25%{left: -100%;}
50%{left: -200%;}
75%{left: -300%;}
100%{left: -400%;}
}
Check this codepen & let me know if it fixes your issue

Related

How to stop two elements effecting each other?

I'm creating an animation https://codepen.io/adsler/pen/bGNWxOe and I've created a div class. I've adjusted this with css. It works. However, as soon as I introduce another div class, it's not only effected by the first, but there seems to be no way of selecting it with css.
So here is the original:
Html:
<div
class="random">four<br>
three<br>zero<br>nine</div>
Css:
.random {background.
color:red;background-image:
linear-gradient(black,
white); width: 10px; height:
200px; font-weight: 900;
position:relative; font-
size:20px; left: 20x;
top:60px; filter:sepia(0);
color:black; border-radius:
100px; box-shadow: 90px 90px
30px 90px #000; text-align:
center;}
.random {animation: turn 30s
ease-in infinite; animation.
direction: alternate.
reverse;animation-delay:
2s;}
#keyframes turn {
0%
{transform:rotate(1400deg);
width: 1px} 30%.
{transform:rotatex(7000deg);
font-size: 30px;} 40%
{transform:rotatez(360deg);
width: 13em} 70%
{width: 10em;}100%
{opacity: 0.9;}
That's fine but then, when I introduce the next sequence, by way of a div class, I can't find the selector with css and the style is influenced by the first div.
<div
class="starring">Starring
</div>
.starring {margin-top: 500px
!important; font-size: 50px
!important;}
So I tried specificity.
.random.starring {margin.
top: 500px
!important; font-size: 50px
!important;}
Still unable to select starring with css and style still influenced by previous div.
In your codepen under the html section you have one too many ending 's in the first part.
Like this:
<div class="random">four<br>three<br>zero<br>nine</div></div>
<div class="starring">Starring</div>
Which should be:
<div class="random">four<br>three<br>zero<br>nine</div>
<div class="starring">Starring</div>
Next thing is - you don't end your animation in your css part
#keyframes turn {
0%{transform:rotate(1400deg);
width: 1px}
30%{transform:rotatex(7000deg);
font-size: 30px;}
40% {transform:rotatez(360deg);
width: 13em}
70% {width: 10em;}100%
{opacity: 0.9;}
Here you need a last } to actually wrap up the turn tag.
Like this:
#keyframes turn {
0%{transform:rotate(1400deg);
width: 1px}
30%{transform:rotatex(7000deg);
font-size: 30px;}
40% {transform:rotatez(360deg);
width: 13em}
70% {width: 10em;}100%
{opacity: 0.9;}
}
Make these changes and it works as supposed.
.starring {
color:red;
}
Works for me.
The problem is you are missing a closing } for your turn keyframe.
#keyframes turn {
0% {
transform:rotate(1400deg);
width: 1px
}
30% {
transform: rotatex(7000deg);
font-size: 30px;
}
40% {
transform: rotatez(360deg);
width: 13em
}
70% {
width: 10em;
}
100% {
opacity: 0.9;
}
}
And then for your second div, this will work:
.starring {
margin-top: 500px !important;
font-size: 50px !important;
}
I feel best solution here would be giving css to 1 element.
Add position:absolute to 1 of the element. And further accordingly adjust the element wherever you want using margin-bottom and margin-left!

How do I make an image push up another image within a <marquee> tag

I am just starting HTML and some basic CSS, Im here trying to make a Rocketship push up another image with some simple tags,
Ive tried everything.
I have right now,
<div align="center" >
<marquee behavior="scroll" direction="up">
<img class="ImageOne" src="images.png">
<img class="ImageTwo" src="falcon9-render.png">
</div>
</marquee>
I have tried some CSS which is in my stylesheet.css right now, and here is that code.
image {
position: relative;
width: 100px;
height: 100px;
border: 1px solid red;
}
.imageOne {
z-index: 0;
}
.imageTwo {
z-index: 1;
}
and at this point, i dont even know if im using z-index in the right context. If its hard to see my vision, Im bascially trying to push and image up with another image under it. or create that kind of visual, i dont know if i have to edit the pixel and align them up. The rocket seems to be being in the center but the src="images.png" is on the side but its under the tag...
Sorry if this is dumb and simple but I couldnt find anything.
As Requested in comments; https://jsfiddle.net/7ohrpk42/
Updated Solution:
img {
margin-left: auto;
margin-right: auto;
display: block;
}
<DOCTYPE HTML!>
<html>
<body bgcolor=“#add8e6”>
<title>The Most Best Worst Websites</title>
<div align="center">
<marquee behavior="scroll" direction="up">
<img class="ImageOne" src="https://i.postimg.cc/g2ZJTkHk/images.png">
<img class="ImageTwo" src="https://i.postimg.cc/mD5W47bx/falcon9-render.png">
</marquee>
</div>
</body>
</html>
Your questions a little unclear without a jsFiddle, but I think you are trying to do something like this:
img {
position: relative;
width: 100px;
height: 100px;
border: 1px solid red;
}
.imageOne {
margin: none;
}
.imageTwo {
margin: none;
}
<div align="center">
<marquee behavior="scroll" direction="up">
<img class="ImageOne" src="https://place-hold.it/20x30">
<br>
<img class="ImageTwo" src="https://place-hold.it/20x30">
</marquee>
</div>
What you're trying to achieve can be done by setting the "f&*k you" image as the background of the marquee and background size to 'cover'. Like this:
marquee{
background: url('https://i.postimg.cc/g2ZJTkHk/images.png') no-repeat;
background-size: cover;
}
I updated your fiddle https://jsfiddle.net/0vd79j2h/
<marquee> is Deprecated
It is strongly recommended that <marquee> be avoided -- it's deprecated and on its way to becoming obsolete. We can still customize HTML elements to behave and appear as a <marquee> with CSS animation (or even with JavaScript/jQuery although it wouldn't be as efficient as CSS). The following demo uses CSS animation only, and the only images are actually fonts (like emoticons)
Demo
.marquee {
width: 30%;
height: 50vh;
/* Required on Parent */
overflow: hidden;
font: 400 15vh/1.5 Consolas;
background: rgba(0, 0, 0, 1);
padding-left: 15px;
margin: 20px auto;
}
.marquee b,
.marquee i {
/* Required on Child*/
white-space: nowrap;
display: table-cell;
vertical-align: baseline;
/* Infinite Loops */
animation: climb 2s linear infinite;
animation-fill-mode: forwards;
/* Set to 0s in order to have a point of reference */
animation-delay: 0s;
}
.marquee i {
animation: fall 2s linear infinite;
}
/* Required for complex CSS animation */
/* Bottom to top / Left to right */
#keyframes climb {
0% {
transform: translate(-200%, 300%);
}
100% {
transform: translate(300%, -300%);
}
}
/* Top to bottom / Right to left */
#keyframes fall {
0% {
transform: translate(200%, -20%);
}
100% {
transform: translate(-300%, 300%);
}
}
<header class='marquee fall'>
<i>🌠</i><em>✨</em>
</header>
<header class='marquee climb'>
<b>🚀</b><em>🌌</em>
</header>

How to create marquee infinite loop of logos slider with css only

Right now my code makes the logos animate from right to left and once it hits the end, it restarts. How can I make it continue in a loop so that the first logo follows the last one when a new cycle starts?
EDIT:
I rather not use extra js libraries, so if there is a simple way of doing this with jquery that would be much better
img {
width: 100px;
}
.marquee {
position: relative;
width: 100%;
height: 100px;
border: 1px solid black;
overflow: hidden;
}
.marquee div {
display: block;
position: absolute;
width: 300%;
overflow: hidden;
animation: marquee 20s linear infinite;
}
.marquee div:hover {
animation-play-state: paused;
}
.marquee span {
float: left;
width: 50%;
}
#keyframes marquee {
0% { left: 0; }
100% { left: -100%; }
}
<div class="marquee">
<div>
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
<img src="http://static.bragdeal.com/logo.png" alt="">
</div>
</div>
I updated your fiddle https://jsfiddle.net/gkpnx34v/2/ --- took a little tinkering, but that should give you the idea.
.tech-slideshow {
height: 100px;
max-width: 100%;
margin: 0 auto;
position: relative;
overflow: hidden;
border:1px solid black;
font-size:0; /* THIS IS A HACK TO REMOVE THE "WHITESPACE" BETWEEN IMAGES.
YOU COULD ALSO PUT ALL OF THE IMAGES ON THE SAME LINE
(eg: <img src=""><img src=""><img src="">
with no spaces or line-breaks),
BUT THAT MAKES THE CODE LESS READABLE SO I'M DOING THIS
FOR THE SAKE OF CREATING THIS EXAMPLE FOR YOU */
}
.mover-1 {
height: 150px;
width: max-content;
position: absolute;
overflow-x:hidden;
top: 0;
left: 0;
animation: moveSlideshow 5s linear infinite;
}
.mover-1 img {
display:inline-block;
vertical-align:middle;
width:100px;
margin:0;
}
#keyframes moveSlideshow {
100% {
transform: translateX(-500px);
}
}
<div class="tech-slideshow">
<div class="mover-1">
<img src="https://placekitten.com/100/150">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/150">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/150">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
<img src="https://placekitten.com/100/100">
</div>
</div>
Set your .mover-1 container's width to max-content (to auto-size to whatever width is necessary). You could also set it to an arbitrary (huge) width just so you won't have to worry about having logos roll over to the next line.
Then set some styles on your images so they'll line up nicely.
Finally, set the moveSlideshow translateX distance to THE EXACT WIDTH OF ONE SET OF LOGOS.
The point is, you want to have 2 sets of logos -- the initial set and then a duplicate that you roll into view. Set your animation to move exactly the width of 1 set and it should loop smoothly.
Just for posterity (and because it's REALLY easy to copy and paste code and doesn't take any extra bandwidth to render) I actually added a 3rd set of logos just to make sure my block of logos was wide enough to never have a gap on wide screens.
P.S. The difference in heights I set on the kitten images (some of them being 150px tall instead of 100px) has nothing to do with the functionality; I just wanted to make sure that you can tell when the animation loops.
P.P.S. Rather than a) manually calculating the total width of the logos or b) adding redundant blocks of logos, you could easily use jQuery to find the width of that .mover-1 container ($('.mover-1')[0].width()) and set your keyframe to move that distance. Then make an array of the images ($('.mover-1 img')), then append/prepend them to the original set.
This code (untested) should get you close:
var logos = $('mover-1 img');
$('.mover-1').append(logos).append(logos);
HTML:
<div class='marquee'>
....
images
....
</div>
CSS:
.marquee {
width: 100%;
overflow: hidden;
border:1px solid #ccc;
}
JavaScript:
$(function () {
$('.marquee').marquee({
duration: 5000,
duplicated: true,
gap: 00,
direction: 'left',
pauseOnHover: true
});
});
This is what i have done to make it run using JQuery Marquee.
External links:
jquery.pause.js
jquery.marquee.min.js
Also you can follow this Fiddle
I know the question says CSS only, but I find all attempts using only keyframes and HTML leads to unwanted spacing between the logo, overlapping logos, parallax effects, etc.
For those willing to use some JavaScript the following works for me:
HTML:
<div id="hold_logos"></div>
CSS:
body {
background: black;
}
#hold_logos {
height: 200px;
background: #218c74;
display: flex;
align-items: center;
margin-top: 100px;
}
.logo {
position: absolute;
cursor: pointer;
width: 140px;
border-radius: 4px;
animation: marquee 10s linear infinite;
}
#keyframes marquee {
0% {
transform: translateX(1400px);
}
100% {
transform: translateX(-200px);
}
}
JS:
images = ["https://www.strunkmedia.com/wp-content/uploads/2018/05/bigstock-221516158.jpg", "https://cms-assets.tutsplus.com/cdn-cgi/image/width=360/uploads/users/2273/posts/32751/image/TwoPeaks-Logo.jpg", "https://png.pngtree.com/png-clipart/20210711/original/pngtree-colorful-nature-logo-png-image_6511888.jpg", "https://designshack.net/wp-content/uploads/symbol-logo-example.jpg", "https://cdn.thebrandingjournal.com/wp-content/uploads/2019/05/chanel_logo_the_branding_journal.jpg"];
const number_of_logos = 5;
const spacing = (window.innerWidth / number_of_logos)*10;
const duration = (number_of_logos*spacing);
var int_cnt = -1;
var marquee = document.getElementById("hold_logos");
partner_interval = setInterval(function() {
int_cnt++;
if(int_cnt < number_of_logos) {
const img = document.createElement("img");
img.className = "logo";
img.src = images[int_cnt];
marquee.append(img);
}
}, spacing/1.4);
setTimeout(function() {
clearInterval(partner_interval);
}, duration);
Result:
The result is smoother than what the GIF shows since it's still using keyframes.
Here's the CodePen.

marquee tag is not working with image tag in HTML

I set marquee tag with an image. But after marquee tag image disappeared. Its not moving. When i remove marquee, image appears.
<div style="margin-top:300px; z-index:100; position:absolute;">
<marquee direction="top" style="margin-top:300px; z-index:1000;
position:absolute;">
<img src="images/cw.jpg" alt=""></marquee>
</div>
I want to marquee image. Please help
you can try this one:
<div style="margin-top:0px; z-index:100; ">
<marquee direction="top" style="margin-top:300px; z-index:1000;
position:absolute;">
<img src="images/cw.jpg" alt="" width="120" height="80" alt="Natural"></marquee>
</div>
Remove position:absolute;
DEMO HERE
OR
DEMO
give styling to div or img and not marquee... and if you want to change image automatically ... You need to change the src content of image tag.. after a specific time interval.
like :
$(function() {
$('#myImage').attr('src', 'image2.gif');
});
if you want to stop the marquee ,.,.,. Run a function after a given interval of time ... in which write:
document.getElementById('Your_marquee_id').stop();
Here is a year 2015 version of the old marquee.
To control of long time the image should "scroll", you alter the animation: marquee 5s linear 3; property.
Now the image scroll time is set to 5 seconds, 3 times, equals 15 seconds and then it stops.
(text scroll time is set to 3 seconds, 5 times, equals 15 seconds)
.marquee {
background-color: #ddd;
width: 500px;
margin: 0 auto;
overflow: hidden;
white-space: nowrap;
text-indent: 100%;
animation: marquee 3s linear 5;
}
.marqueeimg {
width: 500px;
margin: 0 auto;
overflow: hidden;
text-indent: 100%;
animation: marqueeimg 5s linear 3;
}
.marqueeimg:hover,
.marquee:hover {
animation-play-state: paused
}
#keyframes marquee {
0% { text-indent: 80%; }
100% { text-indent: -60%; }
}
#keyframes marqueeimg {
0% { text-indent: 100%; }
100% { text-indent: -70%; }
}
<p class="marquee">this is a simple marquee using css only tech</p>
<br />
<p class="marqueeimg"><img src="http://lorempixel.com/250/150/nature/" alt="image"/></p>

Animate div slider with CSS

I am designing an HTML+CSS slider with automatic transition between slides and infinite duration. I have
this slider on different pages with different content (and number of divs), so I need
to write the same code for everything.
<div class="slide-container">
<div class="slide">div 1 goes here!</div>
<div class="slide">div 2 goes here!</div>
<div class="slide">div 3 goes here!</div>
</div>
I have started with this CSS code and tried with different animations, but I don't know how to do this
.slide-container {
-webkit-animation: transition 2s infinite linear;
-moz-animation: transition 2s infinite linear;
-o-animation: transition 2s infinite linear;
}
EDIT: This is the last transition I used to solve my issue:
#-webkit-keyframes animation {
20%,30% {-webkit-transform: translate(100%);}
70%,100% {-webkit-transform: translate(-100%);}
}
I want to get a div in screen for 5-10 seconds and a transition between divs of 2 seconds (in brackets div that must be on screen at these moment, width=100%, height=50px):
(-start-DIV1 5s)--2s-->(DIV2 5s)--2s-->...-->(DIVN 5s)--2s-->(DIV1 5s)-->...
The reason I do slider with CSS is because I'm trying to avoid JavaScript and JQuery functions.
Below where 12s is defined is the total slide time. This divided by the amount of slides (which in this demo is 3) gives us 4s a slide in this example. This is one method where you can toggle slide time. But like the other poster mentioned you'll still have to customize a bit. My method demonstrates a horizontal slide approach with a smooth transition and fast load time. In any case pure CSS3 is what your after.
JS Poodle.
CSS3 power:
body {
padding: 1em;
background: #999
}
.scrollable {
width: 333px;
margin: 0 auto;
padding: 0;
border:10px solid #fff;
background: #000;
position: relative;
overflow: hidden;
text-align: center;
}
img {
max-width: 333px;
margin: 0;
float:left;
}
.items {
width:999px;
-webkit-animation: hscroll 12s infinite;
-moz-animation: hscroll 12s infinite;
-ms-animation: hscroll 12s infinite;
}
#-webkit-keyframes hscroll {
0% { margin-left: 0; }
27.33% { margin-left: 0 }
33.33% { margin-left: -333px; }
60.66% { margin-left: -333px; }
66.66% { margin-left: -666px; }
94.99% { margin-left: -666px; }
100% { margin-left: 0 }
}
#-moz-keyframes hscroll {
0% { margin-left: 0; }
27.33% { margin-left: 0 }
33.33% { margin-left: -333px; }
60.66% { margin-left: -333px; }
66.66% { margin-left: -666px; }
94.99% { margin-left: -666px; }
100% { margin-left: 0 }
}
#-ms-keyframes hscroll {
0% { margin-left: 0; }
27.33% { margin-left: 0 }
33.33% { margin-left: -333px; }
60.66% { margin-left: -333px; }
66.66% { margin-left: -666px; }
94.99% { margin-left: -666px; }
100% { margin-left: 0 }
}
<div class="scrollable">
<div class="items">
<img src="http://placehold.it/333x500/E8117F/FFFFFF&text=Horizontal"/>
<img src="http://placehold.it/333x500/FFFFFF/E8117F&text=css3"/>
<img src="http://placehold.it/333x500/3D668F/FFFFFF&text=slide show"/>
</div>
</div>
Here is a quick demo that demonstrates some of the techniques you'll need to use. I've used the same HTML markup you provided. This is not a ready-to-go "copy and paste" solution -- you'll need to take some time to understand the code and apply the concept to your particular use-case.
The technique basically involved lining up all the slides side-by-side, then shift the entire row of them every few seconds. The edges will be cropped so that only one slide is shown at a time.
To start with, you'll need to define the size of your "viewing area", by applying a width and height to the .slide-container element. Then apply overflow: hidden to the container, so that slides which aren't in the "viewing area" aren't shown.
Each slide should fill the "viewing area", so apply a width and height of 100% to each .slide element. You'll also need make them display as inline-block elements, so that they are aligned side-by-side, but still fill their container.
Finally, the hard part: defining the animation. Keyframe animations are percentage-based. Basically, since there are three slides, we want to switch after 33% of the animation has elapsed, again after 66%, and return to the beginning after 100%. We want a smooth "slide", so we'll make the actual transition last 5% in total -- so the first one actually starts at 28% and ends at 33%. The keyframes code looks like this:
#keyframes slide {
/* modify percentages to match how many items you have */
0% { margin-left: 0; } /* initial position */
/* (stays in first position ) */
28.333% { margin-left: 0; } /* start sliding */
33.333% { margin-left: -100%; } /* done sliding */
/* (stays in second position ) */
61.667% { margin-left: -100%; } /* start sliding */
66.667% { margin-left: -200%; } /* done sliding */
/* (stays in third position ) */
95% { margin-left: -200%; } /* start sliding */
100% { margin-left: 0; } /* done sliding - back to initial position */
}
And it can be applied to the first slide like this (adjust transition time as desired):
.slide:first-of-type {
animation: slide 10s ease;
animation-iteration-count: infinite;
}
After you've done this, you'll just need to adjust to your preferences. Experiment with slide durations and transition types. Perhaps change how the animation repeats at the end. You can even use the animation-play-state property to pause the animation when you hover over the "viewing window". I've included a full demo below that includes the hover-to-pause feature. If you're not 100% clear about how it works, try removing the overflow: hidden property from the .slide-container element.
#keyframes slide {
0% { margin-left: 0; }
28.333% { margin-left: 0; }
33.333% { margin-left: -100%; }
61.667% { margin-left: -100%; }
66.667% { margin-left: -200%; }
95% { margin-left: -200%; }
100% { margin-left: 0; }
}
.slide-container {
overflow: hidden; /* try commenting this line out! */
width: 150px;
height: 100px;
border: 1px solid #000000;
}
.slide {
display: inline-block;
width: 100%;
height: 100%;
}
.slide:first-of-type {
animation: slide 10s ease;
animation-iteration-count: infinite;
}
.slide-container:hover .slide:first-of-type {
animation-play-state: paused;
}
<div class="slide-container">
<div class="slide" style="background: #ff0000">div 1 goes here!</div><div class="slide" style="background: #00ff00">div 2 goes here!</div><div class="slide" style="background: #0000ff">div 3 goes here!</div>
</div>
Here is the same demo on jsFiddle.