html - Why after refresh the page some jQuery script is not working -
after refresh page jquery script not working. used both $(document).ready(); , $(window).load(); function. code used fit image.
this html code:
<div id="coverpiccontainer"> <img class="cover" src="<?php echo base_url()?>core/uploads/company/<?php echo $cover_image?>" alt="cover"/> </div>`
css code
#coverpiccontainer { width: 100vw; margin-left:-15px; height: 410px; position: relative; overflow: hidden; background-color:#ffffff; border: 1px solid #d3d3d3; } #coverpiccontainer img.wide { display: block; width: 100%; max-height: 100%; height: auto; margin: 0 auto; vertical-align: middle; } #coverpiccontainer img.tall { display: block; max-height: 100%; width: 100%; width: auto; margin: 0 auto; vertical-align: middle; }
and jquery code
$(window).load(function() { $('#coverpiccontainer').find('img').each(function() { var imgclass = (this.width / this.height > 1) ? 'wide' : 'tall'; $(this).addclass(imgclass); }); });
when refresh page time working , time not working. thank great help.
always works here(run, refresh, update): http://jsfiddle.net/l4m9dfby/1/
note: script executed on windows load.
a possible solution particular problem put window.load function
outside of document ready
.
Comments
Post a Comment