I need to set a div height and width according to the first image size within a list of 40 items (all images are the same size). To make it short function works only the first time you load the page, after visiting other pages imgSize will be undefined.
<div id="ulSorList">
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-6 mix">
<div class="portfolio-list">
<a href="#">
<div class="overlay-block"></div>
<img src="/img/1.jpg" class="img-responsive">
</a>
</div>
</div>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-6 mix">
<div class="portfolio-list">
<a href="#">
<div class="overlay-block"></div>
<img src="/img/2.jpg" class="img-responsive">
</a>
</div>
</div>
...
...
...
</div>
Script
$("#ulSorList img:first").load(function() {
imgSize = $(this);
$(".portfolio-list a .overlay-block").width( imgSize.width()).height( imgSize.height() );
alert(imgSize.width());
});
Everything works until you navigate throught the site (new page is loaded).
IT seems like the script is breaking at some point, so I guess that I only need to get the img size of the first list item.
I edited because since i didnt know what could be the problem the question was bad formulated.
Nothing I cant make it work, now it seems like the script isnt breaking and at least I am getting imgSize width, but I am still at the same position. Script wont function after navigaion.
Any ideas?