简体   繁体   中英

Execute jquery function after image has loaded on window resize

I have the following javascript function:

function reglare(){
    alert("Inaltime imagine= "+$(".slider img").height());
}

I call the function on window resize, like this:

$(window).resize(function(){
    reglare();
});

Most of the times the output is the image height, but sometimes the output is 0.

How can I fix this in order to get the actual image size on window resize ALL the times?

LATER EDIT: why do I need this?

The code is like this:

<div id="slideshow" class="latime_100">

        <img src="poze/sageata_st.png" class="navigare" id="navigare_st" onclick="go_prev();"></img>

        <div id="slider_1" class="slider" >

            <img src="../poze/imagine_slide1_iul_fade.png"></img>


        </div>

        <div id="slider_2" class="slider">

            <img src="../poze/imagine_slide2_iul_fade.png"></img>


        </div>

        <div id="slider_3" class="slider">

            <img src="../poze/imagine_slide3_iul_fade.png"></img>


        </div>

        <img src="poze/sageata_dr.png" class="navigare" id="navigare_dr" onclick="go_next();"></img>
    </div>

I have a container div slideshow which is position relative containing more absolute positioned divs. Because they are position absolute, the container does not extend with content so what is below gets overlapped.

Here's a fiddle: https://jsfiddle.net/g6ppqxLf/5/

TO DISPLAY THE ERROR I HAVE IN THE FIDDLE: just resize the browser a few times and follow the alert message: it will sometimes output 0.

the jquery class selector returns an array.

https://api.jquery.com/class-selector/

function reglare(){
  for (var i = 0; i < $("img.slider").length; i++){
    alert($("img.slider")[i].attr("height");
  }
}

this alerts the attribute height of each image with class .slider

hope this is what you searched for

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM