I'm trying to create an animated picture which contains a lot of layers.
In order to have images with right proportions on different screens I use cover css property value(I've tried it for both object-fit for images and background-size for background images). That's why my images on wide screen are croped by the browser.
The problem is that my layers are transformed(mostly rotated and moved) during the animation so there are moments when it is seen the cropped image.
Please see my example below.
How it can be prevented? Or it there some other technique?
body {
margin: 0;
padding: 0;
/*Just to imitate wide screen*/
width: 1000px;
height: 450px;
}
#container {
width: 100%;
height: 100vh;
/*Just to imitate wide screen*/
height: 100%;
overflow: hidden;
position: relative;
}
.layer {
height: 100%;
position: absolute;
width: calc(100% + 20px);
}
.layer img {
height: 100%;
width: 100%;
object-fit: cover;
}
.gulls {
animation: gulls ease-in-out 13s infinite alternate;
}
#keyframes gulls {
from {
transform: rotate(3deg) scaleX(0.95) skew(-10deg, -10deg);
}
to {
transform: rotate(-3deg) scaleX(1.05) skew(10deg, 10deg);
}
}
<div id="container">
<div class="layer">
<img src="https://firebasestorage.googleapis.com/v0/b/wedding-42174.appspot.com/o/animation%2Fsky.png?alt=media&token=25033588-d58c-4616-94e9-4974ec4157a4" alt="">
</div>
<div class="layer gulls">
<img src="https://firebasestorage.googleapis.com/v0/b/wedding-42174.appspot.com/o/animation%2Fgulls5.png?alt=media" />
</div>
</div>
Currently I have this: https://jsfiddle.net/koljada/c08qdw1m/
first of all i have to say that your birds image is a lot bigger then the birds therself (many padding around) as i see the whole image is 2048/1934...
anyway, when you use
object fit:cover he crop;
the image for save the proportion. you can using
object-fit:scale-down;
for save the proportion by scale down the image until he come inside the parent space. i add a quick exemple about how it works down here:
hope it is what you search for..
Images can be cropped with a container div with overflow: hidden; position: relative, So you can position the image inside with position: absolute. The top and left css attribute of the image has to be set a negative value.
The image exact values can be found by using sine and cosine functions.
body {
margin: 0;
padding: 0;
/*Just to imitate wide screen*/
width: 200px;
height: 100px;
}
#container {
width: 100%;
height: 100vh;
/*Just to imitate wide screen*/
height: 100%;
overflow: hidden;
position: relative;
}
.layer {
height: 100%;
position: absolute;
top: -20px;
left: -20px;
width: calc(100% + 20px);
}
.layer img {
height: 150%;
width: 150%;
}
.gulls {
animation: gulls ease-in-out 3s infinite alternate;
}
#keyframes gulls {
from {
transform: rotate(3deg) scaleX(0.95) skew(-10deg, -10deg);
}
to {
transform: rotate(-3deg) scaleX(1.05) skew(10deg, 10deg);
}
}
<div id="container">
<div class="layer gulls">
<img src="http://via.placeholder.com/350x150/000000" />
</div>
</div>
You can use overflow: hidden; position: relative to crop your images after using container div, and using position: absolute at the images to place the image.
Related
I would like to create some css animation on the home page of my site, with some notes falling.
Here is the example: http://labandallonnaise.org/joomla/(link no longer demonstrates behavior)
We can see that the notes are falling, then we have nothing before the next sequence.
Here is the code
.notes-wrapper {
overflow: hidden;
height: 630px;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin-top: -75px;
margin-bottom: -75px;
margin-left: -500px;
margin-right: -500px;
}
.notes {
background: url("gantry-theme://custom/images/background.svg") center !important;
height: 6300px;
animation: fall 10s linear infinite;
overflow: hidden;
z-index: 0;
background-repeat: repeat;
background-size: cover;
top: 0px;
}
.notes img {
animation: none;
background: transparent;
}
#keyframes fall {
0% {
transform: translateY(-1050px);
}
}
<div class="notes-wrapper">
<img style="display: block; margin-left: auto; margin-right: auto; animation: none; background: transparent;" src="images/logo/BandAllonnaisedudule.png" alt="" />
<div class="notes"> </div>
</div>
how can I have continuous animation?
It depends on exactly what effect you want with various viewport aspect ratios.
Whatever the details, you need two copies of the SVG so that you don't get a gap when one has reached the bottom and starts again.
Here's one way to get continuity which puts before and after pseudo elements on the notes div both of which animate down the full height of the viewport. One starts in the viewport, the other above it.
This is a simplistic way of doing it as it doesn't require you to know anything about the aspect ratio of the background image. It would be possible to get better control and produce different results depending on what you'd like to happen on narrow or wide devices. For example, should the notes always fit in completely horizontally, however small they then go? Should there always be only one copy of the background however wide the device and so on.
.notes-wrapper {
overflow: hidden;
position: relative;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
width: 100vw;
height: 100vh;
}
.notes {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
}
.notes::before, .notes::after {
content: '';
background-image: url("https://ahweb.org.uk/background.svg");
position: absolute;
height: 100%;
width: 100%;
animation: fall 10s linear infinite;
overflow: hidden;
z-index: -1;
background-repeat: repeat no-repeat;
background-size: auto 100%;
background-position: center;
}
.notes::before {
top: -100%;
}
.notes::after {
top: 0;
}
#keyframes fall {
100% {
transform: translateY(100vh);
}
}
<div class="notes-wrapper">
<img style="display: block; margin-left: auto; margin-right: auto; animation: none; background: transparent;" src="images/logo/BandAllonnaisedudule.png" alt="" />
<div class="notes"></div>
</div>
How do I zoom in a high quality image, for instance 2000px x 2000px, to the center of a container ? I've tried using transform: scale () but it still makes it scrollable vertically or horizontally. I'm specifically looking for a mobile version. How do I make the image zoomed in centered exactly according to the width of mobile? Using width: 100% doesn't help either. And if I define it like in the code below using pixels it is cropped out on mobile. Do I make it exactly width and height or mobile or? I need it to fully cover whole body and be zoomed in exactly in the center of image. Thanks for you answers. Also zoomed quality is really bad even though it is high quality image.
Basically center and zoom this image so that on mobile it will cover whole screen, spin and look like this:
body {
padding:0;
margin:0;
width: 100%;
height: 100%;
}
#wrap {
transform: scale(2.0);
}
#bg {
width: 1400px;
height: 1400px;
background: url(bg.png);
background-size: contain;
background-position: center center;
-webkit-animation: rotation 9s infinite linear;
}
I have been playing around with this a bit. This is what I ended up with.
Here is the logic that I used figuring this out:
An image rotates around its center.
If I put the image in a container it will cut a part of the image off. The image will still rotate around the center of the image....But that is not the center of the container anymore.
Solution: I made the image behave like background: cover; by using min-width: 100%; and min-height: 100%;
Solution: I centered the image in the container using flexbox.
Another way of centering might be preferable, since the flexbox also affects other children of the container. So any improvements/comments about that would be welcome :).
html
<div id="wrapper">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV0AAAGGCAYAAADYcVJbAAAACXBIWXMAABJ0AAASdAHeZh94AAAZQklEQVR4Xu3dZ3SU15nAcQkMkgBhejej0agCpohiarCxMdhU03sRvRpM7zb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4tgSPXB2UKv4cdTQri+gCwB3y6iVJyeLw3DhBdAFAwTmfoWxb6D8zEF0AuIuLbXziPxTa83eJLgDcRV6tJLk2Nl38R9QBrQiiCwD3ELzY8sXQ7VYjugBwL3EeufyYL2SnkRFdALifeI8UTc8IyaYJogsA5ZBXPykkh+IQXQAop8tdU8S/r3KrGYguAJRTXmKSFM1Ir9RnBqILAA+gwJcsZdsrvmmC6ALAg4jzyJXHUyp80wTRBYAHFQhv8fwMZVTvh+gCQAUUeCt2BCTRBYCKSPDIlf6p4j/4YKsZiC4AVFBenSQpWf5gR0ASXQCohPzUZLn+AG+7RBcAKiPOI9eGp5V7NQPRBYBKym+YJCXlPImM6AJAZQXedq8+lSI3ynHuLtEFgBDIb+KVklX3/1GN6AJAKDjn7va8/9su0QWAUKnhue8SMqILACFU4PGK/8Ddl5ARXQAIJWcJ2cT0u17vQ3QBIMQupiVL6V2OfyS6ABBiebU8UjhVfdg50QWAMLjU3if+Pd//tkt0ASAMnLfd4kXfX8lAdAEgTApSkr/3gxrRBYAwKp773RsmiC4AhNHFzGTx7/3/b7tEFwDCKO/hJCn61tsu0QWAcLp1JoN//823XaILAGEWPG/31glkRBcAwi3wtnulTwrRBQC35NVMkrLdbYguALjlUicf0QUA18R7iC4AuInoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuIjoAoCLiC4AuMYj/we1S/LYDKJ7aQAAAABJRU5ErkJggg==" id="image"/>
</div>
css
#keyframes zoom-effect {
0% {
transform: scale(1) rotate(0deg);}
100% {
transform: scale(4) rotate(360deg);}
}
#wrapper{
height: 250px;
width: 350px;
border: 2px solid green;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
#image{
z-index: -100;
min-height: 100%;
min-width: 100%;
animation-name: zoom-effect;
animation-duration: 9s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
Hope it helps :)
Set width: 100% and remove background-size: contain:
JSFiddle
#bg {
width: 100%;
height: 500px;
background: url(http://placehold.it/1000x1000);
background-position: center;
background-repeat: no-repeat;
}
<div id="bg"></div>
and if you want to use these styles for the body, add background-attachment: fixed:
JSFiddle
body {
padding:0;
margin:0;
width: 100%;
height: 100%;
background: url(http://placehold.it/1000x1000);
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
}
You could use background-size: 200% combined with background-position: -50%, -50% or a similar proportion (300% size vs. -100% position offset)
Example:
.x {
width: 400px;
height: 300px;
margin: 100px;
background: url(http://placehold.it/400x400/fa0);
background-size: 300%;
background-position: -100%, -100%;
}
<div class="x">
</div>
About rotation: You can rotate the whole thing, but not the background image alone, so you have to use two DIVs: Put one rotating div into another (smaller) div that has overflow: hidden.The rotating DIV has to have position: absolute and z-index: -1 to remain in the background.
Here's that situation in action:
.y {
width: 400px;
height: 300px;
margin: 100px;
overflow: hidden;
position: relative;
}
.x {
position: absolute;
width: 800px;
height: 600px;
left: -200px;
top: -100px;
z-index: -1;
background: url(http://placehold.it/400x400/fa0);
background-size: 300%;
background-position: -100%, -100%;
animation: move 5s infinite linear;
}
#keyframes move {
100% {transform: rotate(360deg);}
}
<div class="y">
Any content here.
<div class="x">
</div>
</div>
I have an idea for an Ajax-loader.
This is what I have accomplished so far:
body {
background-color: lightGrey;
counter-reset: h1-counter;
}
.wrap {
max-width: 200px;
height: 50px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrap div {
background: linear-gradient(#0032f0, white, #0032f0);
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
opacity: .8;
}
.wrap div.dark-bar {
position: absolute;
width: 10%;
height: 100%;
animation: moveDarkBar 3s linear infinite;
z-index: 1;
}
#keyframes moveDarkBar {
from {
left: -20%;
}
to {
left: 120%;
}
}
<div class="wrap">
<div></div>
<div class="dark-bar"></div>
</div>
I want the moving indicator (.dark-bar) to be "melted" with foreground-div. Currently there is a hard line which is visually distinguishable.
Is there a way to get the moving indicator (.dark-bar) to be blurred on the left-, right edge?
You could make use of CSS filter to add blur to top layer which is animated as below,
filter - The filter property provides graphical effects like blurring,
sharpening, or color shifting an element. Filters are commonly used to
adjust the rendering of images, backgrounds, and borders.
Do include vendor prefixes for other browsers such as -webkit-,-o-,-moz-,-ms- to filter.
body {
background-color: lightGrey;
counter-reset: h1-counter;
}
.wrap {
max-width: 200px;
height: 50px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrap div {
background: linear-gradient(#0032f0, white, #0032f0);
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
opacity: .8;
}
.wrap div.dark-bar {
position: absolute;
width: 10%;
height: 100%;
animation: moveDarkBar 3s linear infinite;
z-index: 1;
-webkit-filter:blur(2px); /*Add this*/
}
#keyframes moveDarkBar {
from {
left: -20%;
}
to {
left: 120%;
}
}
<div class="wrap">
<div></div>
<div class="dark-bar"></div>
</div>
Try using the box-shadow property and set the vertical and horizontal axis values to 0. Something like this:
div {
box-shadow: 0 0 10px black;
}
This might be a similar effect for the one you want.
Is it possible to have a body background image aligned to the edge of a container element?
Using boostrap 3, I want a background to the page that is fixed to a container edge, so when resizing, the background moves with the container (ie, in the example below, the background image centered over the container edge):
(source: nfx.nz)
Is this possible with a background image, or would I have to add a new absolutely positioned layer / or javascript...?
There are several solutions to your question, and it really depends on if you require dynamic sizing of the background. The example I have shown will animate the container dynamically, so you can see how it works.
Approach No. 1: Offset background position with known value
One is if you know the exact dimensions of the image, then you can simply position it negatively along the x-axis (i.e. moving it to the left) by half the width of the image. This is assuming that you are not dynamically sizing your background image:
* {
margin: 0;
padding: 0;
}
div {
background-color: steelblue;
background-image: url('http://placehold.it/400x200');
background-repeat: no-repeat;
background-position: -200px 0;
width: 50%;
margin: 0 auto;
height: 500px;
animation-name: pulse;
animation-duration: 3s;
animation-iteration-count: infinite;
}
#keyframes pulse {
0% {
width: 50%;
}
50% {
width: 100%;
}
100% {
width: 50%;
}
}
<div>
Background image dimension: 400x200
</div>
Approach No. 2: Use pseudo/dummy element
If your background size is dynamic (i.e. changes with the size of the container), you are better off using an absolutely positioned pseudo-element or a dummy element:
* {
margin: 0;
padding: 0;
}
div {
background-color: steelblue;
width: 50%;
margin: 0 auto;
height: 500px;
animation-name: pulse;
animation-duration: 3s;
animation-iteration-count: infinite;
position: relative;
overflow: hidden;
}
div::before {
background-image: url('http://placehold.it/400x200');
background-repeat: no-repeat;
background-size: 100%;
content: '';
position: absolute;
top: 0;
bottom: 0;
left: -50%;
right: 50%;
}
div > * {
position: relative;
}
#keyframes pulse {
0% {
width: 50%;
}
50% {
width: 100%;
}
100% {
width: 50%;
}
}
<div>
<p>Background image dimension: 400x200</p>
</div>
I'm trying to display a panoramic image with a specific size and a hidden overflow to eventually enable user-induced panning (the code is not included below).
I'm adding the image this way:
<div class="pan">
<img src="http://lorempixel.com/image_output/sports-q-c-1920-480-7.jpg">
</div>
I am setting the image size parameters this way:
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid;
}
However, when I change the width, the height changes proportionally, and I don't have any overflow to hide. The image is 13632 × 2936.
This is the result I get from the code above:
When setting the size this way, I get the image below:
.pan {
width: 400px;
height: 400px;
overflow: hidden;
border: red solid;
}
Trying to override img parameters set to 100% (for other purposes), I get a distorted image--still no hidden overflow:
.pan img {
height: 800px;
width: 400px;
transition: opacity .6s linear .8s;
}
Other code related to .pan and a container (from tutorial cited below) :
.pan img{
transition: opacity .6s linear .8s;
}
.pan img.loaded{ opacity: 1; }
.img-pan-container, .img-pan-container img{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
.img-pan-container{
position: relative;
overflow: hidden;
cursor: crosshair;
height: 100%;
width: 100%;
}
.img-pan-container img{
-webkit-transform: translateZ(0); -ms-transform: translateZ(0); transform: translateZ(0);
position: absolute;
top: 0;
left: 0;
}
For info, I am trying to implement this example. However, I am not currently focusing my question on the rest of the panning code, as I am having issues just getting the image sized correctly with the hidden overflow.
The img child has to be larger than the parent .pan, see snippet below with an image of 1920px width and 480px height. But this will crop parts of the image.
Snippet
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display:block /* fix inline gap */
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
UPDATE
Based on your updated question, it is most likely you have in your css img set as max-width:100%, see the same snippet above with that property set.
Snippet
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display:block; /* fix inline gap */
max-width:100% /* YOUR ISSUE */
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
UPDATE OP's Comment:
This may be the case...How can I override img for only this class?
If you can't find the origin and/or want to keep the max-width:100% for other imgs you can override by using max-width:none on .pan > img
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display: block; /* fix inline gap */
max-width: 100% /* YOUR ISSUE */
}
.pan > img {
max-width: none
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
You can try to archive cover effect for image using this css:
.pan {
...
position: relative;
}
img {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
transform: translate(-50%, -50%);
}
JSFiddle here