Last active
July 3, 2019 07:42
-
-
Save ArtemSites/111519956f9ad974ae2e35a59fdea9cc to your computer and use it in GitHub Desktop.
Lazy Load img video audio iframe
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
jQuery(function() { | |
lazyLoad($('body')); | |
}); | |
function lazyLoad($content) { | |
$content.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){ | |
$(this).attr('src', $(this).data('src')); | |
$(this).removeAttr('data-src'); | |
if($(this).is('source')){ | |
$(this).closest('video').get(0).load(); | |
} | |
}); | |
} |
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
<video width="320" height="240" controls> | |
<source data-src="movie.mp4" type="video/mp4"> | |
<source data-src="movie.ogg" type="video/ogg"> | |
Your browser does not support the video tag. | |
</video> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment