Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <img id="photo"
- src="a_really_big_file.jpg"
- alt="this is some alt text"
- title="this is some title text" />
- $(function()
- {
- var REAL_WIDTH = $("#photo").width();
- var REAL_HEIGHT = $("#photo").height();
- $(window).resize(adjust_photo_size);
- adjust_photo_size();
- function adjust_photo_size()
- {
- if(REAL_HEIGHT < 150)
- {
- REAL_WIDTH = $("#photo").width();
- REAL_HEIGHT = $("#photo").height();
- if(REAL_HEIGHT < 150)
- {
- //image not loaded.. try again in a quarter-second
- setTimeout(adjust_photo_size, 250);
- return;
- }
- }
- var new_width = . . . ;
- var new_height = . . . ;
- $("#photo").width(Math.round(new_width));
- $("#photo").height(Math.round(new_height));
- }
- });
- <img id="photo"
- onload="photoLoaded();"
- src="a_really_big_file.jpg"
- alt="this is some alt text"
- title="this is some title text" />
- //This must be outside $() because it may get called first
- var isPhotoLoaded = false;
- function photoLoaded()
- {
- isPhotoLoaded = true;
- }
- $(function()
- {
- //Hides scrollbars, so we can resize properly. Set with JS instead of
- // CSS so that page doesn't break with JS disabled.
- $("body").css("overflow", "hidden");
- var REAL_WIDTH = -1;
- var REAL_HEIGHT = -1;
- $(window).resize(adjust_photo_size);
- adjust_photo_size();
- function adjust_photo_size()
- {
- if(!isPhotoLoaded)
- {
- //image not loaded.. try again in a quarter-second
- setTimeout(adjust_photo_size, 250);
- return;
- }
- else if(REAL_WIDTH < 0)
- {
- //first time in this function since photo loaded
- REAL_WIDTH = $("#photo").width();
- REAL_HEIGHT = $("#photo").height();
- }
- var new_width = . . . ;
- var new_height = . . . ;
- $("#photo").width(Math.round(new_width));
- $("#photo").height(Math.round(new_height));
- }
- });
- <img id="photo"
- onload='loaded(this.id)'
- src="a_really_big_file.jpg"
- alt="this is some alt text"
- title="this is some title text" />
- $("#photo").load(function() {
- alert("Hello from Image");
- });
- doShow = function(){
- if($('#img_id').attr('complete')){
- alert('Image is loaded!');
- } else {
- window.setTimeout('doShow()',100);
- }
- };
- $('#img_id').attr('src','image.jpg');
- doShow();
- <img id="myimage" onload="$(this).data('loaded', 'loaded');" src="lolcats.jpg" />
- if ($('#myimage').data('loaded')) {
- // loaded, so do stuff
- }
Add Comment
Please, Sign In to add comment