Show Loading Gif While Full Image Loading

user5314029

So basically I need to

$("img#icon").click(function() {

// start loading FullImg and FadeIn loading gif

// while full image is loading get its height like this below

$("img#FullImg").load(function(){
  var imgHeight = $(this).height();
});

// when FullImg loaded, FadeOut Gif and then animate block and FadeIn FullImg

    $("#block").animate({
        height: '+='ImgHeight
    },
    function() {
        $("img#FullImg").fadeIn("slow");
    });

}

Do I need some sort of AJAX for this?

kolunar

jquery.ajax only accepts xml, html, script, plain text and json datatype.

dataType (default: Intelligent Guess (xml, json, script, or html))

Ref: http://api.jquery.com/jquery.ajax/

Or use Base64 image data something like data:image/png;base64,iVBORw0KGgoAAAANSUhE... and load it from a webservice

Or you shall create an img tag on the fly and put the src property to url something like below,

$.fn.image = function(src, callback) {
   return this.each(function() {
         var i = new Image();
         i.src = src;
         i.onload = callback;
         this.appendChild(i);
   });
}

$("#btnLoadImg").on("click", function() {
   var container = $("div#container");
   $('#overlay').show();
   container.image("https://i.imgur.com/9fEliNr.jpg",function(){
      $('#overlay').hide();
      container.fadeIn();
   });	
});
#container {
   display: none;
}
#overlay {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    background: #000;
    opacity: 0.8;
    filter: alpha(opacity=80);
	display: none;
}
#loading {
    width: 50px;
    height: 57px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -28px 0 0 -25px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnLoadImg" type="button">Load Image</button>
<div id="container"></div>
<div id="overlay"><img id="loading" src="https://i1.wp.com/cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif"></div>

Ref: https://msankhala.wordpress.com/2012/08/29/loading-image-through-ajax/

See also a similar question here Asynchronously load images with jQuery

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Show loading gif while image is loading

From Dev

Show loading gif image while running client-side code

From Dev

How to show a loading gif image while a page loads

From Dev

jQuery: trying to show loading gif while div is loading

From Dev

Show Loading gif on hover

From Dev

Show an "Loading..." image while background loading of image with Picasso

From Dev

Show an "Loading..." image while background loading of image with Picasso

From Dev

How to show loading image while product list still loading in prestashop

From Dev

Show loading image while PHP is executing

From Dev

Show loading image while ajax being executed

From Dev

Show default element while loading Image

From Dev

show loading image while server process the request

From Dev

Show loading image while uploading files

From Dev

How to show image while page is loading in swift?

From Dev

How to show loading gif while page hasn't fully loaded

From Dev

How to show a loading gif while an APi is being called in xamarin android?

From Dev

Error while loading image

From Dev

How do I show a loading image while script is working?

From Dev

Android show progress bar while image loading dynamically

From Dev

Android : Show loading image while check & download xml file

From Dev

Show image while loading data into gridView - vb.net

From Dev

How do I show a loading image while script is working?

From Dev

Loading a full width and height image

From Dev

how to make html inactive and show loading gif

From Dev

display loading gif in specific a div while ajax loading

From Dev

globally trigger 'loading gif' while ALL images are loading (display inline)

From Dev

Loading gif while form.submit()

From Dev

Show a loading gif logo while content is loaded using thread in java swing

From Dev

Adding a gif image as an android loading icon?

Related Related

  1. 1

    Show loading gif while image is loading

  2. 2

    Show loading gif image while running client-side code

  3. 3

    How to show a loading gif image while a page loads

  4. 4

    jQuery: trying to show loading gif while div is loading

  5. 5

    Show Loading gif on hover

  6. 6

    Show an "Loading..." image while background loading of image with Picasso

  7. 7

    Show an "Loading..." image while background loading of image with Picasso

  8. 8

    How to show loading image while product list still loading in prestashop

  9. 9

    Show loading image while PHP is executing

  10. 10

    Show loading image while ajax being executed

  11. 11

    Show default element while loading Image

  12. 12

    show loading image while server process the request

  13. 13

    Show loading image while uploading files

  14. 14

    How to show image while page is loading in swift?

  15. 15

    How to show loading gif while page hasn't fully loaded

  16. 16

    How to show a loading gif while an APi is being called in xamarin android?

  17. 17

    Error while loading image

  18. 18

    How do I show a loading image while script is working?

  19. 19

    Android show progress bar while image loading dynamically

  20. 20

    Android : Show loading image while check & download xml file

  21. 21

    Show image while loading data into gridView - vb.net

  22. 22

    How do I show a loading image while script is working?

  23. 23

    Loading a full width and height image

  24. 24

    how to make html inactive and show loading gif

  25. 25

    display loading gif in specific a div while ajax loading

  26. 26

    globally trigger 'loading gif' while ALL images are loading (display inline)

  27. 27

    Loading gif while form.submit()

  28. 28

    Show a loading gif logo while content is loaded using thread in java swing

  29. 29

    Adding a gif image as an android loading icon?

HotTag

Archive