download image first, then apply fadeIn
i have this code that works
- <head>
- <script type="text/javascript">
- $(function () {
- var img = new Image();
- $(img).load(function () {
- $(this).hide();
- $('#divContent').append(this);
- $(this).fadeIn();
- }).attr('src', 'images/main.jpg');
- });
- </script>
- </head>
- <body>
- <div id="divContent"></div>
- </body>
but this code limits 1 image and the name of the image is placed inside the js function.
my question is:
can i alter this code or can someone share an idea to write a more generic version so that i can download the image first THEN apply some jQuery to it like:
- <head>
- <script type="text/javascript">
- $(function () {
- var img = new Image();
- $(img).load(function () {
- $(this).hide();
- $('#divContent').append(this);
- $(this).fadeIn();
- }).attr('src', 'APPLY TO THE DIV HERE');
- });
- </script>
- </head>
- <body>
- <div id="divContent"><img src="images/main.jpg" /></div>
- </body>