Glide.js, how to check size of image?

Karolina

I am using Glide.js to create a slider and I have a problem, I don't know how to check size of image inside slide. I must display picture in this slide in actual ratio, i mean if picture have height larger then width I should use in css height:100%; width:auto; In other way if width is larger than height it should be width:100%, height:auto. And this is my problem, I don't know how to do this. I am a begginer in javascript. I can write something in jQuery, but i don't know if this is correct. My slider look like:

<div class="slider" id="paintSlider">
                                    <ul class="slides">
                                        <li class="slide paint">
                                            <span> <img src="img/glowna_tlo.jpg" alt=""> </span>
                                        </li>
                                        <li class="slide paint">
                                            <span> <img src="img/NORWAY-FIRE-COMMUNICATION.jpg" alt=""> </span>
                                        </li>
                                        <li class="slide paint">
                                            <span> <img src="img/taipei-fireworks.png" alt=""> </span>
                                        </li>
                                        <li class="slide paint">
                                            <span> <img src="img/00003761.jpg" alt=""> </span>
                                        </li>
                                        <li class="slide paint">
                                            <span> <img src="img/super-squirrel.png" alt=""> </span>
                                        </li>
                                        <li class="slide paint">
                                            <span> <img src="img/searing-mountain.png" alt=""> </span>
                                        </li>
                                    </ul>
                                </div>

JQuery:

`var imgS = $("#paintSlider slides slides img");

    var wysokosc = imgS.height();

    var szerokosc = imgS.width();


    if(wysokosc > szerokosc){
        imgS.css(["height","100%"] ["width","auto"]);
    }
    else if(wysokosc<szerokosc){
        imgS.css(["height","auto"] ["width","100%"]);
    }
    else{
        imgS.css(["height","100%"] ["width","100%"]);
    }`

Could you tell me how to do this :

flowstoneknight

You can limit the image sizes using max-height:100% and max-width:100% in CSS.

Here's a fiddle.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to check image size before download

Glide, possible to get image file size (not dimensions)?

How to priorly get future Glide image size which will be stored in cache in Android/Java? [Not solved]

How to round an image with Glide library?

How to databinding image loading with Glide?

How to make an image glide in javascript?

How to check size of array in Angular Js?

How to set image size for js tooltip

Android Glide: How to download bitmap at specific size?

How to check an image dimensions using js or node

How to check size and extension of an image before upload in Aurelia-Typescript?

Android - How to Load Image by name using Glide

How to load image using glide in advance?

How to Intent an image that loaded from the internet by glide

How to Save image into local storage loaded with Glide?

How set image into ImageView using Glide and a URI?

How to get width and height of an image from Glide

Glide android: How to cache a byteArray image?

How to make border for circle cropped image in glide

How to use glide library for slider image in android

How to rotate an image in Glide to be right side up

How to crossfade between old and new image in Glide

How to show image from server into Glide in android

How to fit Image into ImageView using Glide

How to reload image in Glide from the same url?

How to set the background image for textview with Glide?

How to apply animation on cached image in Glide

How to show image (Bitmap) in compose with glide, coil

How to display different image after another with Glide?