jq 图片延迟加载

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>图片延迟加载</title>
<style>
*{margin:0;padding:0;list-style:none}
li{
float: left;
width: 400px;
height: 400px;
margin: 50px;
}
li img{
width: 100%;
height: 100%;
}
</style>
<script src=”http://code.jquery.com/jquery-1.7.2.min.js”></script>
<script>
$(function(){
function img(){
var aImg=$(‘#ul li img’);
var oScrollTop=$(document).scrollTop();
var oClientH=$(window).height();
aImg.each(function(index,element){
var oTop=$(element).offset().top;
var oSrc=$(element).attr(‘_src’);
if(oScrollTop+oClientH>oTop){
$(element).attr(‘src’,oSrc);
$(element).removeAttr(‘_src’);
}
});
}

$(window).bind({
‘scroll’:img,
‘load’ : img,
‘resize’: img
});

});
</script>

</head>
<body>
<ul id=”ul”>
<li><img _src=”img/a%20(1).jpg”></li>
<li><img _src=”img/a%20(2).jpg”></li>
<li><img _src=”img/a%20(3).jpg”></li>
<li><img _src=”img/a%20(4).jpg”></li>
<li><img _src=”img/a%20(5).jpg”></li>
<li><img _src=”img/a%20(6).jpg”></li>
<li><img _src=”img/a%20(7).jpg”></li>
<li><img _src=”img/a%20(8).jpg”></li>
<li><img _src=”img/a%20(9).jpg”></li>
<li><img _src=”img/a%20(10).jpg”></li>
</ul>
</body>
</html>

转【http://www.w3cfuns.com/notes/31062/147c7651eacc0e614046b4d4b166daaa.html】

Comments (6,611)

  1. homes for sale bethesda 20816

    Hello there! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any tips?

  2. how to promote maxbounty offers

    Pretty! This was a really wonderful post. Thanks for providing this info.

  3. food for puppies

    This is my first time pay a visit at here and i am really impressed
    to read all at alone place.

  4. מצלמות אבטחה לבית

    Marvelous, what a webpage it is! This website gives helpful facts to us,
    keep it up.

  5. William Vance

    I truly love your blog.. Pleasant colors & theme. Did you build this site yourself? Please reply back as I’m hoping to create my own blog and would love to learn where you got this from or exactly what the theme is named. Appreciate it!

  6. http://pu.Lockiele.com/

    Thanks for another informative site. The place else may just I get that kind of info
    written in such a perfect method? I’ve a undertaking that I’m just now working on, and I have been on the look out for such information.

  7. roller coasters

    Everything is very open with a precise clarification of the issues.
    It was truly informative. Your website is extremely helpful.
    Many thanks for sharing!

  8. adult dvd sales

    Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is important and all. However think of
    if you added some great photos or video clips to
    give your posts more, “pop”! Your content is excellent but
    with images and videos, this website could definitely be
    one of the very best in its niche. Superb blog!

  9. Nashville tn painting contractor

    Howdy! This is my 1st comment here so I just wanted to give a quick shout out and tell you I truly enjoy reading through
    your blog posts. Can you suggest any other blogs/websites/forums that
    deal with the same topics? Thanks!

  10. Ofertas especiales

    Everything is very open with a very clear
    description of the challenges. It was definitely
    informative. Your website is useful. Thank you for sharing!

  11. 窓ガラスの修理交換

    どうもです。
    とつぜんの書き込みでごめんなさい。

    玄関のドアのガラスを引越し中に夜に粉々にしてくれてしんどかったですよ、ほとほと。
    わたしもだいぶ途方にくれましたがが、あの業者にお願いしてので良さげになりましたよ。

    ばいなら~

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注