Created
March 15, 2012 03:32
-
-
Save kozo002/2041709 to your computer and use it in GitHub Desktop.
画像のonloadイベントを扱う際のjQuery拡張
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($) { | |
| var imageLoad = function(callback) { | |
| var src, timestamp; | |
| src = this.attr('src'); | |
| timestamp = new Date().getTime(); | |
| this.attr({src: src + '?' + timestamp}); | |
| return this.load(callback); | |
| }; | |
| var createImageAndLoad = function(image_path, callback) { | |
| var createImage = function(image_path) { | |
| return $('<img />').attr({src: image_path}); | |
| }; | |
| if (typeof image_path === 'string') { | |
| createImage(image_path).imageLoad(callback); | |
| } else if (typeof image_path === 'object') { | |
| $.each(image_path, function(i, imgp) { | |
| createImage(imgp).imageLoad(callback); | |
| }); | |
| } | |
| }; | |
| $.fn.extend({ | |
| imageLoad: imageLoad | |
| }); | |
| $.extend({ | |
| imageLoad: createImageAndLoad | |
| }); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment