javascript - Maintaining Aspect Ratio with 100% Width & Height (Cropping Overflow in CSS) -
i'm working on full-screen background slideshow.
my question is: how can set image take full screen , maintain aspect ratio?
min-height , min-width work, not keep aspect ratio when both set. want image cropped full coverage of container.
i believe need have 1 dimension fixed, , other auto; given image dimensions , view-port dimensions variable, i'm thinking need @ least 2 sets of css rules, , javascript calculate 1 should used. there simpler way this?
i've drawn diagram illustrating problem. dark colors original images. median colors desired effect. lighter colors desired overflow scaled image.
i'm working on ken-burns effect full-screen background. know have worry transitions, i'm hoping can handle after.
tutorial ken burns effect:
http://cssmojo.com/ken-burns-effect/
solved: maju introducing me background cover. changing images divs , changing javascript + css on ken burns code images divs worked well. script changes element class, have use maju's css way or change script.
if use images in css background-image, can set on element background-size. , if understand right, need like:
.background { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-repeat: no-repeat !important; background-position: 0 0 !important; background-attachment: fixed !important; -webkit-background-size: cover !important; -moz-background-size: cover !important; -o-background-size: cover !important; background-size: cover !important; }
<div class="background" style="background-image: url(http://www.jurosko.cz/images/stackoverflow.png)"></div>
cover affect image in way cover whole element right aspect ratio.
there new css style, doesn't work in ie/me.
https://css-tricks.com/almanac/properties/o/object-fit/
for reason recommend use divs background-image.
Comments
Post a Comment