-
-
Save kobitoDevelopment/125e1c8d28db618c85a115969608e787 to your computer and use it in GitHub Desktop.
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
.lazy { | |
display: none; | |
} |
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
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="jquery.lazyload.min.js"></script> | |
</head> | |
<body> | |
<img class="lazy" data-src="遅延読み込み表示させたい画像パス" src="遅延読み込みされるまで表示されるダミー画像パス"> | |
<noscript> | |
<img src="JavaScriptオフ時に表示させたい画像パス"> | |
</noscript> | |
</body> | |
<!-- ---------------------------------------------------- | |
スクロール値を利用するscriptと併用する場合、 | |
lazyloadを実装する<img>にはcssもしくはwidth height属性で | |
幅、高さを指定する必要あり | |
------------------------------------------------------ --> | |
<!-- loading属性を使用する場合 --> | |
<img loading="lazy" src="画像パス"> | |
<iframe loading="lazy" src="コンテンツパス"></iframe> | |
<picture> | |
<source srcset="画像パス"> | |
<source srcset="画像パス"> | |
<img loading="lazy" src="画像パス"> | |
</picture> |
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() { | |
$('.lazy').show(); | |
$('.lazy').lazyload(); //.lazy部分は希望のclass名で可 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment