|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
6 |
<title>Loading Images Below the Fold</title> |
|
|
7 |
|
|
|
8 |
<style type="text/css"> |
|
|
9 |
/*margin and padding on body element |
|
|
10 |
can introduce errors in determining |
|
|
11 |
element position and are not recommended; |
|
|
12 |
we turn them off as a foundation for YUI |
|
|
13 |
CSS treatments. */ |
|
|
14 |
body { |
|
|
15 |
margin:0; |
|
|
16 |
padding:0; |
|
|
17 |
} |
|
|
18 |
</style> |
|
|
19 |
|
|
|
20 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
21 |
<script type="text/javascript" src="../../build/yui/yui-debug.js"></script> |
|
|
22 |
|
|
|
23 |
<!--there is no custom header content for this example--> |
|
|
24 |
|
|
|
25 |
</head> |
|
|
26 |
|
|
|
27 |
<body class=" yui-skin-sam"> |
|
|
28 |
|
|
|
29 |
<h1>Loading Images Below the Fold</h1> |
|
|
30 |
|
|
|
31 |
<div class="exampleIntro"> |
|
|
32 |
<p>Often pages will have a number of images below the fold, hidden from the user's view. These are prime candidates to load with the <a href="http://developer.yahoo.com/yui/imageloader/">ImageLoader Utility</a>.</p> |
|
|
33 |
|
|
|
34 |
<p>All the images in this example belong to the same group, and each loads immediately only when it appears above, or within the specified distance (25px) of, the page fold.</p> |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
</div> |
|
|
38 |
|
|
|
39 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
40 |
|
|
|
41 |
<style> |
|
|
42 |
|
|
|
43 |
.everything .cont { border:1px solid #888; width:100px; margin:75px 50px; } |
|
|
44 |
.everything .right { margin-left:300px; } |
|
|
45 |
#img1Cont { height:75px; margin-top:25px; } |
|
|
46 |
#img2Cont { height:67px; } |
|
|
47 |
#img3Cont { height:53px; } |
|
|
48 |
#img4Cont { height:72px; } |
|
|
49 |
#img5Cont { height:75px; margin-bottom:25px; } |
|
|
50 |
|
|
|
51 |
</style> |
|
|
52 |
|
|
|
53 |
|
|
|
54 |
<div class='everything' id='everything'> |
|
|
55 |
<div class='cont' id='img1Cont'> |
|
|
56 |
<img id='img1' /> |
|
|
57 |
</div> |
|
|
58 |
<div class='cont right' id='img2Cont'> |
|
|
59 |
<img id='img2' /> |
|
|
60 |
</div> |
|
|
61 |
<div class='cont' id='img3Cont'> |
|
|
62 |
<img id='img3' /> |
|
|
63 |
</div> |
|
|
64 |
<div class='cont right' id='img4Cont'> |
|
|
65 |
<img id='img4' /> |
|
|
66 |
</div> |
|
|
67 |
<div class='cont' id='img5Cont'> |
|
|
68 |
<img id='img5' /> |
|
|
69 |
</div> |
|
|
70 |
</div> |
|
|
71 |
|
|
|
72 |
|
|
|
73 |
<script> |
|
|
74 |
|
|
|
75 |
YUI({base:"../../build/", timeout: 10000, filter:"debug", logInclude: {imageloader:true, example:true}}).use("imageloader", function(Y) { |
|
|
76 |
|
|
|
77 |
var foldGroup = new Y.ImgLoadGroup({ name: 'fold group', foldDistance: 25 }); |
|
|
78 |
foldGroup.registerImage({ domId: 'img1', srcUrl: 'http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/small/museum.jpg' }); |
|
|
79 |
foldGroup.registerImage({ domId: 'img2', srcUrl: 'http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/small/uluru.jpg' }); |
|
|
80 |
foldGroup.registerImage({ domId: 'img3', srcUrl: 'http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/small/katatjuta.jpg' }); |
|
|
81 |
foldGroup.registerImage({ domId: 'img4', srcUrl: 'http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/small/morraine.jpg' }); |
|
|
82 |
foldGroup.registerImage({ domId: 'img5', srcUrl: 'http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/small/japan.jpg' }); |
|
|
83 |
|
|
|
84 |
/* |
|
|
85 |
var foldGroup = new YAHOO.util.ImageLoader.group(window, 'scroll'); |
|
|
86 |
foldGroup.foldConditional = true; |
|
|
87 |
//foldGroup.addTrigger(window, 'resize'); |
|
|
88 |
foldGroup.name = 'fold_group'; |
|
|
89 |
*/ |
|
|
90 |
|
|
|
91 |
/* |
|
|
92 |
* This uncustomary wait before adding the resize trigger is done specifically to cater to IE for this example. |
|
|
93 |
* In IE and with the Logger enabled, IE fires an immediate resize event while rendering the Logger module, consequently loading all the images in the example. |
|
|
94 |
* This 200 ms delay allows IE to render the Logger without interference. |
|
|
95 |
* In your code, you would add the resize trigger in a straightforward fashion, as is documented in the example. |
|
|
96 |
*/ |
|
|
97 |
//YAHOO.util.Event.addListener(window, 'load', function() { setTimeout("foldGroup.addTrigger(window, 'resize')", 200); }); |
|
|
98 |
|
|
|
99 |
}); |
|
|
100 |
|
|
|
101 |
</script> |
|
|
102 |
|
|
|
103 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
104 |
|
|
|
105 |
</body> |
|
|
106 |
</html> |