All I want to have a background scrolling effect from bottom to top ,but I dont know how to do so. I have tried it using CSS ,but the problem arises here is it scroll in both direction i.e bottom to top and top to bottom.
* {
margin: 0;
padding: 0;
}
div {
width: 100vw;
height: 100vh;
animation: change 2s infinite ease-in both;
background-image: url(http://hdwallpaperbackgrounds.net/wp-content/uploads/2016/07/background-pictures-2.jpg);
background-size: cover;
background-repeat: no-repeat;
}
#keyframes change {
0%, 100% {
background-position: 0% 5%;
}
5% {
background-position: 0% 10%
}
10% {
background-position: 0% 15%
}
15% {
background-position: 0% 20%
}
20% {
background-position: 0% 25%
}
25% {
background-position: 0% 30%;
}
30% {
background-position: 0% 35%
}
35% {
background-position: 0% 40%
}
40% {
background-position: 0% 45%
}
45% {
background-position: 0% 50%
}
}
<div>
<h1> This is animating background ...</h1>
</div>
You can achieve that by just using the to and from attributes for the keyframes change. The effect is kind of weird, because the background top and bottom do not fit together...
* {
margin: 0;
padding: 0;
}
div {
width: 100vw;
height: 100vh;
animation: change 3s linear infinite;
background-image: url(http://hdwallpaperbackgrounds.net/wp-content/uploads/2016/07/background-pictures-2.jpg);
background-size: cover;
background-repeat: repeat-y;
background-position: 0 0;
}
#keyframes change {
from {
background-position: 0 100vh;
}
to {
background-position: 0 0;
}
}
<div>
<h1> This is animating background ...</h1>
</div>
Related
I'd like to have a wavy background on top of my regular background but the image is not stretching all the way out. It has to be position absolute (otherwise it's interfering with my navigation and moves it down by the height of the img). JSFiddle. I already tried object-fit: fill which also didn't work. Thanks in advance
My code:
* {
margin: 0;
padding: 0;
font-family: helvetica;
}
body {
height: 5000px;
}
#background {
position: absolute;
width: 100%;
height: 100%;
object-fit: contain;
object-position: ;
opacity: 15%;
}
#navwrapper {
background: linear-gradient(250deg, #0061ff, #60efff);
background-size: 400% 400%;
-webkit-animation: AnimationName 10s ease infinite;
-moz-animation: AnimationName 10s ease infinite;
animation: AnimationName 10s ease infinite;
height: 100vh;
}
#-webkit-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#-moz-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
<nav id="navwrapper">
<div id="background"><img src="https://i.postimg.cc/RZzwCTQz/Zeichenfla-che-92.png"></div>
</nav>
Instead of applying css to #background apply it in #background img thats where you want to change object fit property.
replace this
#background {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
object-position: ;
opacity: 15%;
}
with this
#background img{
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 15%;
}
You can check the output below
* {
margin: 0;
padding: 0;
font-family: helvetica;
}
body {
height: 5000px;
}
#background img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
object-position: ;
opacity: 15%;
}
#navwrapper {
background: linear-gradient(250deg, #0061ff, #60efff);
background-size: 400% 400%;
-webkit-animation: AnimationName 10s ease infinite;
-moz-animation: AnimationName 10s ease infinite;
animation: AnimationName 10s ease infinite;
height: 100vh;
}
#-webkit-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#-moz-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
<nav id="navwrapper">
<div id="background"><img src="https://i.postimg.cc/RZzwCTQz/Zeichenfla-che-92.png"></div>
</nav>
Use this property
#background{
background:url(...);
background-position: center !important;
background-size: cover !important;
background-repeat: no-repeat;
height: 500px;
width:100%
}
You can just set width and height to 100% for an image that it should all space of container:
#background img {
width: 100%;
height: 100%;
}
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.
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>
I'm trying to do animation with my background image and I manage to do it. But I my animation is not running smoothly. If I reduce the animation from 30s to 5s it running smooth but the animation is too fast.
My CSS :
body {
height: 100%;
width: 100%;
background: url('https://static.pexels.com/photos/3768/sky-sunny-clouds-cloudy.jpg') center center no-repeat;
background-size: cover;
background-position-y: 0;
animation: grow 30s linear infinite;
}
#keyframes grow {
0% { background-size: 100% auto; }
50% { background-size: 140% auto; }
100% { background-size: 100% auto; }
}
Check the result here https://jsfiddle.net/6q3obw82/
Try changing the keyframes for the code with adding more breakpoints
#keyframes grow {
0% { background-size: 100% auto; }
25% { background-size: 150% auto; }
50% { background-size: 200% auto; }
75% { background-size: 150% auto; }
100% { background-size: 100% auto; }
}
Jsfiddle link: https://jsfiddle.net/xgjmesrr/
I've got this code working for changing background conteniosly in CSS and HTML:
animation: animated 10s linear infinite;
#keyframes animated {
0% { background-position: 0px bottom; }
25% { background-position: -200px bottom; }
50% { background-position: -400px bottom; }
75% { background-position: -600px bottom; }
}
Currently the background moves in an animation, but I would like to have the background switch position in one go - so it seems the image changes instead of moving.
Is that possible with only CSS?
What you need to do is, instead of
25% { background-position: -200px bottom; }
50% { background-position: -400px bottom; }
You do it like:
25.01%, 50% { background-position: -200px bottom; }
50.01%, 75% { background-position: -400px bottom; }
Thus you will almost eliminate the time needed for transition from one keyframe to another.
Demo: jsFiddle
*{ padding:0; margin:0; }
#bg{ width:100%; height:100vh;
background: url('//www.planwallpaper.com/static/images/Fall-Nature-Background-Pictures.jpg') no-repeat;
animation: slideshow 5s infinite;
}
#keyframes slideshow {
0%, 25% { background-position: 0px bottom; }
25.01%, 50% { background-position: -200px bottom; }
50.01%, 75% { background-position: -400px bottom; }
75.01%, 100% { background-position: -600px bottom; }
}
<div id="bg"></div>
Use the following:
animation: animated 10s steps(4) linear infinite;
#keyframes animated {
from {
background-position: 0px 0px; }
to {
background-position: 600px 0px; }
}
You can remove linear in your CSS
animation: animated 10s infinite;
#keyframes animated {
0% { background-position: 0px bottom; }
25% { background-position: -200px bottom; }
50% { background-position: -400px bottom; }
75% { background-position: -600px bottom; }
}
You need to use some JS with setTimeout of 10000ms to switch background-position
$(document).ready(function () {
var koef = 1;
setInterval(function () {
$('#image').css({'background-position-x': 600 * -koef});
koef = !koef;
}, 1000);
});
#image {
width: 200px;
height: 200px;
background: url(http://lorempixel.com/g/1000/200/) no-repeat 0 bottom;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="image"></div>