How to make responsive png sequence? - html

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.

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.

Animation Width Compared to Background Image

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.

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);

CSS Buttons with 'particular' animation

Does anyone have any idea on how to implement an HTML+CSS button that once clicked has an animation like this one?
Source: http://www.materialup.com/posts/shinebutton
Thanks for the help!
with Twitter's "fave" animation
.heart {
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: url(https://cssanimation.rocks/images/posts/steps/heart.png) no-repeat;
background-position: 0 0;
cursor: pointer;
animation: fave-heart 1s steps(28);
}
.heart:hover {
background-position: -2800px 0;
transition: background 1s steps(28);
}
#keyframes fave-heart {
0% {
background-position: 0 0;
}
100% {
background-position: -2800px 0;
}
}
<div class="heart"></div>
More

Chrome decodes large image every frame

I'm trying to do some interactive map, where I'm using two very large images (3200x800 and 4096x1024 pixels). Problem is, that Chrome decode image with clouds every frame... so performance is really poor (example in snippet).
Found similar problem here, but didn't help. I'm using Chrome 43 (64-bit) on Linux Mint 17.1 (64-bit). I also tried Firefox and without problem...
html, body {
height: 100%;
}
body {
margin: 0;
overflow: hidden;
}
div {
position: absolute;
width: 3200px;
height: 1800px;
background: url('http://i.imgur.com/p1Jf722.png'), url('http://i.imgur.com/zUkgN3j.jpg');
animation: clouds 200s linear infinite;
transition: 5s;
left: 0;
top: 0;
}
#keyframes clouds {
from { background-position: 0 0, left top; }
to { background-position: 4096px 0, left top; }
}
body:hover > div {
left: -500px;
top: -250px;
}
<div></div>
Using a pseudo element and transform still uses a lot of CPU, but it is quite smoother. And it absolutely eliminates the image decodes.
I think that Chrome is using a single buffer for a div background. When you change the relative positions of the 2 images in this buffers, it becomes invalid and has to be rendered decoded again. Probably FF can allocate an intermediate buffer for every image, even if used in the same background
html, body {
height: 100%;
}
body {
margin: 0;
overflow: hidden;
}
div {
position: absolute;
width: 3200px;
height: 1800px;
background: url('http://i.imgur.com/zUkgN3j.jpg');
transition: 5s;
left: 0;
top: 0;
background-position: left top;
transform: translateZ(0px);
}
div:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
background: url('http://i.imgur.com/p1Jf722.png');
animation: clouds 200s linear infinite;
transition: 5s;
left: 0;
top: 0;
transform: translateZ(0px);
}
#keyframes clouds {
from { background-position: 0 0; }
to { background-position: 4096px 0; }
}
body:hover > div {
left: -500px;
top: -250px;
}
<div></div>
There are probably multiple ways to do improve performance here, but the lowest hanging fruit is just to offload everything onto the GPU by adding a non-distorting transform to your div. Voila, no more image decodes.
html, body {
height: 100%;
}
body {
margin: 0;
overflow: hidden;
}
div {
position: absolute;
width: 3200px;
height: 1800px;
background: url('http://i.imgur.com/p1Jf722.png'), url('http://i.imgur.com/zUkgN3j.jpg');
animation: clouds 200s linear infinite;
transition: 5s;
left: 0;
top: 0;
transform: translateZ(0);
}
#keyframes clouds {
from { background-position: 0 0, left top; }
to { background-position: 4096px 0, left top; }
}
body:hover > div {
left: -500px;
top: -250px;
}
<div></div>