JavaScript DHTML/YUI Library/ImageLoader — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 13:02, 26 мая 2010

Basic Features of the ImageLoader Utility

   <source lang="html4strict">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Basic Features of the ImageLoader Utility</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/imageloader/imageloader-min.js"></script>

</head> <body class=" yui-skin-sam">

Basic Features of the ImageLoader Utility

Displayed here are the basic abilities of the <a href="http://developer.yahoo.ru/yui/imageloader/">ImageLoader Utility</a>. Images are loaded only after triggers are fired or time limits are reached.

Hover over each image to show its triggers and its time limit. Try tripping the triggers to see the load reactions. Refresh the page to reset the images.

<style> .everything { position:relative; height:420px; } .everything div { border:1px solid #888; } .topmain { position:absolute; top:10px; left:120px; height:75px; width:100px; } .duo1 { position:absolute; top:130px; left:20px; height:67px; width:100px; } .duo2 { position:absolute; top:130px; left:220px; height:53px; width:100px; } .png { position:absolute; top:240px; left:140px; height:34px; width:61px; } .scroll { position:absolute; top:320px; left:120px; height:72px; width:100px; } </style>

   <img id="scrollImg" style="visibility:hidden;" />

<script> var mainGroup = new YAHOO.util.ImageLoader.group("topmain", "mouseover", 2); mainGroup.registerBgImage("topmain", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/museum.jpg"); mainGroup.name = "group 1"; var duoGroup = new YAHOO.util.ImageLoader.group("duo1", "mouseover", 4); duoGroup.registerBgImage("duo1", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/uluru.jpg"); duoGroup.registerBgImage("duo2", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/katatjuta.jpg"); duoGroup.addTrigger("duo2", "click"); duoGroup.name = "group 2"; var pngGroup = new YAHOO.util.ImageLoader.group(null, null, 5); pngGroup.registerPngBgImage("pngimg", "http://us.i1.yimg.ru/us.yimg.ru/i/us/nws/weather/gr/47s.png"); pngGroup.name = "group 3"; var scrollGroup = new YAHOO.util.ImageLoader.group(window, "scroll"); var scrollImg = scrollGroup.registerSrcImage("scrollImg", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/morraine.jpg"); scrollImg.setVisible = true; scrollGroup.name = "group 4"; </script>

</body> </html>


 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


ImageLoader with TabView

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>ImageLoader with TabView</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/tabview/assets/skins/sam/tabview.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/imageloader/imageloader-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/tabview/tabview-min.js"></script>

</head> <body class=" yui-skin-sam">

ImageLoader with TabView

Here we demonstrate integrating the <a href="http://developer.yahoo.ru/yui/imageloader/">ImageLoader Utility</a> with the <a href="http://developer.yahoo.ru/yui/tabview/">TabView Control</a>.

Also illustrated are the considerations for the ImageLoader group triggers, as they involve some reasoning on the developer"s part.

Here, each tab contains images and a corresponding ImageLoader group. Triggers are set as mouseover events of each tab.

<html>

<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.ru/2.2.2/build/tabview/assets/border_tabs.css"> <style type="text/css">

  1. demo { width:350px; }
  2. demo .yui-content { padding:20px; } /* pad content container */
  3. demo img { margin-right:20px; }
  4. tabone, #tabtwo, #tabthree { height:80px; }

</style>

  • <a href="#tabone">Tab One</a>
  • <a href="#tabtwo">Tab Two</a>
  • <a href="#tabthree">Tab Three</a>
     <img id="imgTwo" title=""imgTwo"" />
     <img id="imgThree" title=""imgThree"" />
     <img id="imgFour" title=""imgFour"" />
     <img id="imgFive" title=""imgFive"" />

<script> var tabView = new YAHOO.widget.TabView("demo"); var tabTwoImageGroup = new YAHOO.util.ImageLoader.group("tabTwoLabel", "mouseover"); tabTwoImageGroup.registerSrcImage("imgTwo", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/uluru.jpg"); tabTwoImageGroup.registerSrcImage("imgThree", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/katatjuta.jpg"); tabTwoImageGroup.addTrigger("tabTwoLabel", "focus"); tabTwoImageGroup.name = "tab_two_group"; var tabThreeImageGroup = new YAHOO.util.ImageLoader.group("tabThreeLabel", "mouseover"); tabThreeImageGroup.registerSrcImage("imgFour", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/morraine.jpg"); tabThreeImageGroup.registerSrcImage("imgFive", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/japan.jpg"); tabThreeImageGroup.addTrigger("tabThreeLabel", "focus"); tabThreeImageGroup.name = "tab_three_group";

</script> </html>

</body> </html>


 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Loading Images Below the Fold

   <source lang="html4strict">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Loading Images Below the Fold</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/imageloader/imageloader-min.js"></script>

</head> <body class=" yui-skin-sam">

Loading Images Below the Fold

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.ru/yui/imageloader/">ImageLoader Utility</a>.

All the images in this example belong to the same group, and all load immediately only if they appear above the fold of the page.

<style> .everything .cont { border:1px solid #888; width:100px; margin:25px 50px; } .everything .right { margin-left:300px; }

  1. img1Cont, #img5Cont { height:75px; }
  2. img2Cont { height:67px; }
  3. img3Cont { height:53px; }
  4. img4Cont { height:72px; }

</style>

   <img id="img1" />
   <img id="img2" />
   <img id="img3" />
   <img id="img4" />
   <img id="img5" />

<script> var foldGroup = new YAHOO.util.ImageLoader.group(window, "scroll"); foldGroup.registerSrcImage("img1", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/museum.jpg"); foldGroup.registerSrcImage("img2", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/uluru.jpg"); foldGroup.registerSrcImage("img3", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/katatjuta.jpg"); foldGroup.registerSrcImage("img4", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/morraine.jpg"); foldGroup.registerSrcImage("img5", "http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/japan.jpg"); foldGroup.foldConditional = true; //foldGroup.addTrigger(window, "resize"); foldGroup.name = "fold_group"; /*

* This uncustomary wait before adding the resize trigger is done specifically to cater to IE for this example.
* 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.
* This 200 ms delay allows IE to render the Logger without interference.
* In your code, you would add the resize trigger in a straightforward fashion, as is documented in the example.
*/

YAHOO.util.Event.addListener(window, "load", function() { setTimeout("foldGroup.addTrigger(window, "resize")", 200); }); </script>

</body> </html>


 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Using ImageLoader with CSS Class Names

   <source lang="html4strict">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Using ImageLoader with CSS Class Names</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/imageloader/imageloader-min.js"></script>

</head> <body class=" yui-skin-sam">

Using ImageLoader with CSS Class Names

The <a href="http://developer.yahoo.ru/yui/imageloader/">ImageLoader Utility</a> allows you an alternate method of using CSS class names to load images.

Hover over each image to show its triggers and limit. Try tripping the triggers to see the load reactions. Refresh the page to reset the images.

<style> .everything { position:relative; height:420px; } .everything div { border:1px solid #888; } .topmain { position:absolute; top:10px; left:120px; height:75px; width:100px; } .duo1 { position:absolute; top:130px; left:20px; height:67px; width:100px; } .duo2 { position:absolute; top:130px; left:220px; height:53px; width:100px; } .scroll { position:absolute; top:320px; left:120px; height:72px; width:100px; } .yui-imgload-maingroup, .yui-imgload-duogroup, .yui-imgload-scrollgroup

 { background:none !important; }

</style>

   <img id="scrollImg" class="yui-imgload-scrollgroup" style="background-image:url("http://developer.yahoo.ru/yui/docs/assets/examples/exampleimages/small/morraine.jpg");" src="http://us.i1.yimg.ru/us.yimg.ru/i/us/tr/b/1px_trans.gif" width="100" height="72" />

<script> var mainGroup = new YAHOO.util.ImageLoader.group("topmain", "mouseover", 2); mainGroup.className = "yui-imgload-maingroup"; mainGroup.name = "group 1"; var duoGroup = new YAHOO.util.ImageLoader.group("duo1", "mouseover", 4); duoGroup.className = "yui-imgload-duogroup"; duoGroup.addTrigger("duo2", "click"); duoGroup.name = "group 2"; var scrollGroup = new YAHOO.util.ImageLoader.group(window, "scroll"); scrollGroup.className = "yui-imgload-scrollgroup"; scrollGroup.name = "group 3"; </script>

</body> </html>


 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>