Animation Width Compared to Background Image - html

I have a background image that resizes automatically based on screen size. I have an animation that I'm trying to get to do the same thing for consistency. However, the animation doesn't appear to be the same width or won't stretch across the entire screen.
body {
height: 100%;
margin: 0;
padding: 0;
background:url(../img/Ex.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
padding-top: 3rem;
outline-style: solid;
outline-color: #ffcd11;
outline-width: thick;
background-color: #ffcd11;
}
.rain {
height: 100%;
margin: 0;
padding: 0;
background:url(../img/snowfall2.png) center center
fixed,url(../img/snowfall3.png) center center fixed;
animation: rain 1s linear infinite;
}
.rain:before {
content: '';
position: absolute;
height: 100%;
background: white;
animation: lighting 4s linear infinite;
opacity: 0;
}
#keyframes lighting {
0%
{
opacity: 0;
}
10%
{
opacity: 0; position: 0% 0%;
}
11%
{
opacity: 1; position: 20% 100%;
}
14%
{
opacity: 0;
}
20%
{
opacity: 0;
}
21%
{
opacity: 1;
}
24%
{
opacity: 0;
}
104%
{
opacity: 0;
}
}
#keyframes rain {
0%
{
background-position: 0% 0%;
}
100%
{
background-position: 20% 100%;
}
}
<div class="carousel-caption rain">
<!-- <h1>Machine Parts Intelligence</h1> -->
<h1 class="lead">THE NEW MACHINE MODEL INFORMATION EXPERIENCE</h1>
</div>
Keyframes have been added. I haven't quite gotten the lighting effect to work as I want to, but I'm not really concerned about that at the moment. I just want the rain/snowfall effect to be the same width as the background image itself.

I just need to add the following code in my CSS:
.rain {
height: 100%;
margin: 0;
padding: 0;
left: 0;
right: 0;
background:url(../img/snowfall2.png) center center fixed,url(../img/snowfall3.png)
center center fixed;
animation: rain 1s linear infinite;
}
A left and right function took care of my issue and it expanded the width of my website.

It's difficult to know what you were going for without actually having the images or a visual representation of your goal, but this is my best guess as to what you wanted.
The main change I made was to adjust the background-position property within your keyframe to have 50% as the first value, effectively positioning it in the center of the element. Since it's named rain, I also made it fall from above to below.
body {
height: 100%;
margin: 0;
padding: 0;
background:url('https://images-na.ssl-images-amazon.com/images/I/51IwmuOPQyL._SL1052_.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
padding-top: 3rem;
outline-style: solid;
outline-color: #ffcd11;
outline-width: thick;
background-color: #ffcd11;
}
.rain {
height: 100%;
margin: 0;
padding: 0;
background:url('https://www.ikea.com/gb/en/images/products/euphorbia-acrurensis-potted-plant__0654026_pe708251_s5.jpg') center center
fixed, url('https://media.istockphoto.com/photos/cactus-in-pot-picture-id486466536?k=6&m=486466536&s=612x612&w=0&h=3CJO4XNOcS3WtAdMU4A9TuCbcwxnE9Rr6lHU4GDSwhE=') center center fixed;
animation: rain 1s linear infinite;
}
.rain:before {
content: '';
position: absolute;
height: 100%;
background: white;
animation: lighting 4s linear infinite;
opacity: 0;
}
#keyframes lighting {
0%
{
opacity: 0;
}
10%
{
opacity: 0; position: 0% 0%;
}
11%
{
opacity: 1; position: 20% 100%;
}
14%
{
opacity: 0;
}
20%
{
opacity: 0;
}
21%
{
opacity: 1;
}
24%
{
opacity: 0;
}
104%
{
opacity: 0;
}
}
#keyframes rain {
0%
{
background-position: 50% 100%;
}
100%
{
background-position: 50% 0%;
}
}
<div class="carousel-caption rain">
<!-- <h1>Machine Parts Intelligence</h1> -->
<h1 class="lead">THE NEW MACHINE MODEL INFORMATION EXPERIENCE</h1>
</div>
Let me know if this wasn't what you intended and I'll see if I can adjust it.

Related

Slideshow animation bug

I have slideshow on my page, but I have small bug in animation and I can't find it.
I use slideshow according to this tutorial: https://www.youtube.com/watch?v=TzAshjkhFQw .
But I want to have only 3 slides not 4.
First 3 slides are ok, but instead of the fourth there is an empty background. I want only 3 slides and after that repeat slideshow.
/* Slider */
.slider {
display: block;
height: 100%;
width: 100%;
z-index: -1;
background-color: #1f1f1f;
overflow: hidden;
position: absolute;
top: 0px;
right: 0px;
border-bottom: 10px solid rgb(121, 0, 0);
}
.slider > * {
position: absolute;
display: block;
width: 100%;
height: 100%;
background-color: #1f1f1f;
animation: slide 12s infinite;
overflow: hidden;
}
.slide:nth-child(1) {
left: 0%;
animation-delay: -1s;
background-image: url(img/slide1.jpg);
background-size: cover;
background-position: center;
}
.slide:nth-child(2) {
left: 100%;
animation-delay: 2s;
background-image: url(img/slide2.png);
background-size: cover;
background-position: center;
}
.slide:nth-child(3) {
left: 100%;
animation-delay: 5s;
background-image: url(img/slide3.jpg);
background-size: cover;
background-position: center;
}
.slide p {
font-size: 2rem;
text-align: center;
display: inline-block;
width: 100%;
margin-top: 340px;
color: #fff;
}
#keyframes slide {
0% { left: 100%; width: 100%; opacity: 1;}
5% { left: 0%;}
25% { left: 0%;}
30% { left: -100%; width: 100%; opacity: 1;}
30.0001% { left: -100%; width: 0%; opacity: 0;}
100% { left: 100%; width: 0%; opacity: 0;}
}
<div class="slider">
<div class="slide">
<p>Slide1</p>
</div>
<div class="slide">
<p>Slide2</p>
</div>
<div class="slide">
<p>Slide3</p>
</div>
</div>
Thank you in advance for your advice!
You need to change the percentages in the animations as well as the timings on the individual slides
#keyframes slide {
0% { left: 100%; width: 100%; opacity: 1;}
6.667% { left: 0%;}
33.334% { left: 0%;}
40% { left: -100%; width: 100%; opacity: 1;}
40.0001% { left: -100%; width: 0%; opacity: 0;}
100% { left: 100%; width: 0%; opacity: 1;}
}
.slide:nth-child(2) {
animation-delay: 3s;
}
.slide:nth-child(3) {
animation-delay: 7s;
}
The animation was initially designed for 4 slides in 12 seconds, i.e. one slide every 3 seconds. If you want to change that to one slide every 4 seconds, you need to space the animations further apart (change the animation delay), and also change the animation so that the slide is visible for a longer time (multiply each percentage by 4/3).
This way of animating slides seems really inflexible however, so you might want to look at some other approach, which allows you to add or remove slides more easily.

Gradient under a image

i want to make a gradient go under my wave effect so when you scroll down the wave fades away by using a gradient.
My CSS code:
section {
width: 100%;
height: 100vh;
}
section .wave:before {
content: '';
width: 100%;
height: 143px;
background: url(images/wave2.png);
position: absolute;
top: 0;
left: 0;
opacity: 0.8;
animation: wave-reverse 15s linear infinite;
}
section .wave {
position: absolute;
width: 100%;
height: 143px;
bottom: 0;
left: 0;
background: url(images/wave2.png);
animation: wave 10s linear infinite;
}
section .wave:after {
content: '';
width: 100%;
height: 143px;
background: url(images/wave2.png);
position: absolute;
top: 0;
left: 0;
opacity: 0.6;
animation-delay: -5s;
animation: wave 15s linear infinite;
}
#keyframes wave {
0% {
background-position: 0;
}
100% {
background-position: 1360px;
}
}
#keyframes wave-reverse {
0% {
background-position: 1360px;
}
100% {
background-position: 0;
}
}
.waveGradient {
width: 100%;
top: 100px;
bottom: 0;
background-image: linear-gradient(#429bf4, transparent);
}
My HTML code for this:
<section>
<div class="wave">
</div>
<div class="waveafter"></div>
</section>
images:
this is what its like when you load up the page.
image 1
Gradient goes under the wave image to make it look like it fades away.
Image 2

<div> Background image transparent but NOT text [duplicate]

This question already has answers here:
Can I set an opacity only to the background image of a div?
(8 answers)
Closed 4 years ago.
I am trying to create a <div> that has a slow panning transparent background, as part of an HTML module in opencart. It being a module, styling has to be self contained.
What I have so far:
<style>
#keyframes backgroundScroll {
0% { background-position: 50% 50%; }
33% { background-position: 1% 50%; }
40% { background-position: 1% 50%; }
66% { background-position: 99% 50%; }
75% { background-position: 99% 50%; }
100% { background-position: 50% 50%; }}
/* added pauses to each edge of the image */
#mtn-scroll {
width: 800px;
height: 100%;
background: url(coolpanoramapicture.jpg) no-repeat; opacity:0.1;
background-size: 250%;
background-position: 50% 50%;
animation: backgroundScroll 60s ease-in-out 1s infinite; }
</style>
<div id="mtn-scroll">
<div>
Content text goes here!
</div>
</div>
What I want is for opacity to NOT affect the text as well. Ive heard the bell ring about using ::before, but I have no idea where the hammer hangs. Was I onto something?
Does anyone know how to make ONLY the background image go transparent, without having to resort to finagling with a transparent PNG file?
You were on the right track with the ::before pseudo-element. Here's how to implement it:
html,
body {
height: 100%;
}
#mtn-scroll {
width: 800px;
height: 100%;
position: relative;
}
#mtn-scroll::before {
background: url('https://i.imgur.com/4HLnakJ.jpg') no-repeat;
opacity: 0.1;
background-size: 250%;
background-position: 50% 50%;
animation: backgroundScroll 60s ease-in-out 1s infinite;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
content: '';
}
#mtn-scroll div {
position: relative;
}
#keyframes backgroundScroll {
0% {
background-position: 50% 50%;
}
33% {
background-position: 1% 50%;
}
40% {
background-position: 1% 50%;
}
66% {
background-position: 99% 50%;
}
75% {
background-position: 99% 50%;
}
100% {
background-position: 50% 50%;
}
}
<div id="mtn-scroll">
<div>
Content text goes here!
</div>
</div>

Create dynamically changing background images with animation

I'm trying to create a background image which changes every few seconds with an animation so the next image slides in from the right at the same time as the other image slides out.
Currently I have a code without animation; it works fine, however the images take ages to load. Is this just because my image files are too large? Is there a way to make them load faster?
My current code is:
HTML:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
var header = $('body');
var backgrounds = new Array(
'url(DSC_0007.jpg)'
, 'url(DSC_01110.jpg)'
, 'url(DSC_0277.jpg)'
, 'url(DSC_0050.jpg)'
);
var current = 0;
function nextBackground() {
current++;
current = current % backgrounds.length;
header.css('background-image', backgrounds[current]);
}
setInterval(nextBackground, 5000);
header.css('background-image', backgrounds[0]);
});
</script>
CSS:
body{
background: url(DSC_0007.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
I'm very new to coding so would appreciate any help, thanks in advance!
You can use CSS animation.
img#bg1 {
min-height: 100%;
min-width: 100%;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
animation: background1 60s ease 0s infinite;
}
img#bg2 {
min-height: 100%;
min-width: 100%;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
animation: background2 60s ease 0s infinite;
margin-left: -100%;
}
img#bg3 {
min-height: 100%;
min-width: 100%;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
animation: background3 60s ease 0s infinite;
margin-left: -100%;
}
img#bg4 {
min-height: 100%;
min-width: 100%;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
animation: background4 60s ease 0s infinite;
margin-left: -100%;
}
#keyframes background1 {
0% { margin-left: -0%; }
20% { margin-left: -0%; }
25% { margin-left: 100%; }
26% { margin-left: -100%; }
95% { margin-left: -100%; z-index: 1; }
100% { margin-left: -0%; z-index: 1; }
}
#keyframes background2 {
0% { margin-left: -100%; }
20% { margin-left: -100%; }
25% { margin-left: -0%; }
45% { margin-left: -0%; }
50% { margin-left: 100%; }
100% { margin-left: -0%; }
}
#keyframes background3 {
0% { margin-left: -100%; }
45% { margin-left: -100%; }
50% { margin-left: -0%; }
70% { margin-left: -0%; }
75% { margin-left: 100%; }
100% { margin-left: -0%; }
}
#keyframes background4 {
0% { margin-left: -100%; }
70% { margin-left: -100%; }
75% { margin-left: -0%; }
95% { margin-left: -0%; }
100% { margin-left: 100%; }
}
<img id="bg1" src="http://download-wallpaper.net/images/nature-background/nature-background-24.jpg">
<img id="bg2" src="http://wallpapercave.com/wp/pwQMS6f.jpg">
<img id="bg3" src="http://all4desktop.com/data_images/original/4236532-background-images.jpg">
<img id="bg4" src="http://wallpaper-gallery.net/images/background-desktop-wallpaper-hd/background-desktop-wallpaper-hd-9.jpg">
#JamesDouglas has answered to your first question. But Regarding your second question, In your JS, you have set the slide change time to "5000" milliseconds, that's why the slides are taking ages to change. Change it to 1000 milliseconds, The slides will change faster than before. Hope this helps.
setInterval(nextBackground, 1000);

How to make responsive png sequence?

I am trying make responsive png sequences.
My tried code is here. What is wrong with code?
1. if i removed background-size :100%; it shows image until and unless it is invisible.
2. It is not responsive. (if i comment background-size :100%)
CSS
.eye {
position: relative;
width: 70%;
margin: -10% auto 0 auto; /* positioning tweak */
}
.pngseq{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: url('http://arnoculus.com/img/eye-sprite.png') no-repeat 0 0%;
background-size: 100%;
animation: play 3s steps(58) infinite;
}
#-webkit-keyframes play {
from { background-position: 0px; }
to { background-position: -30740px; }
}
#-moz-keyframes play {
from { background-position: 0px; }
to { background-position: -30740px; }
}
#-ms-keyframes play {
from { background-position: 0px; }
to { background-position: -30740px; }
}
#-o-keyframes play {
from { background-position: 0px; }
to { background-position: -30740px; }
}
#keyframes play {
from { background-position: 0px; }
to { background-position: -30740px; }
}
HTML
<div class="eye">
<div class="pngseq">
</div>
</div>
JSFIDDLE
You have several mistakes...
Here is your code working
.eye {
position: relative;
width: 70%;
height: 800px;
background-color: red;
margin: -10% auto 0 auto; /* positioning tweak */
}
.pngseq{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: url('http://arnoculus.com/img/eye-sprite.png') no-repeat 0 0%;
background-size: 5800%;
animation: play 3s steps(57) infinite;
}
#keyframes play {
from { background-position: 0px 0px; }
to { background-position: 100% 0px; }
}
<div class="eye">
<div class="pngseq">
</div>
</div>
It is shaking a bit, maybe the original image isn't accurate, or maybe working with percentages at this sizes has some rounding error; I don't know for sure.