source: trunk/inc/js/jquery.dolPromo.js

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 2.2 KB
Line 
1(function($){
2 $.fn.dolPromo = function(iInterval, iTransition) {
3
4 function moveToCenter($img, bHide) {
5
6 if (!$img.is('img') || !$img.width() || !$img.height() || !$img.parent().width() || !$img.parent().height())
7 return false;
8
9
10 // place the image on the center and crop it (if neccessary) using parent
11 $img.parent().css({
12 overflow: 'hidden',
13 position: 'relative'
14 });
15
16 $img.css({
17 position: 'absolute',
18 left: Math.round( ($img.parent().width() / 2) - ($img.width() / 2)),
19 top: Math.round( ($img.parent().height() / 2) - ($img.height() / 2))
20 });
21
22 if (bHide)
23 $img.hide();
24 }
25
26 function switchNextImg($promo, iTransition) {
27 var $curImg = $('img:visible', $promo);
28 var $nextImg = $curImg.next();
29
30 if (!$nextImg.length)
31 var $nextImg = $('img:first', $promo);
32
33 $curImg.fadeOut(iTransition);
34 $nextImg.fadeIn(iTransition);
35 }
36
37 var iInterval = iInterval || 3000; //switching interval in milliseconds
38 var iTransition = iTransition || 1000; //transition (fadeIn|fadeOut) time
39
40 var $promo = this;
41
42 $('img', $promo)
43 .each(function(iIndex) {
44
45 var $img = $(this);
46 var bHide = (iIndex > 0); // do not hide only first
47
48 if($img.width() && $img.height()) {
49 moveToCenter($img, bHide);
50 } else {
51 // attach event on load
52 if( document.all ) { //ie
53 $img.ready(function(){
54 moveToCenter($img, bHide);
55 });
56 } else {
57 $img.load(function(){
58 moveToCenter($img, bHide);
59 });
60 }
61 }
62 });
63
64 // begin switching
65 setInterval(function(){
66 switchNextImg($promo, iTransition);
67 }, iInterval);
68 };
69})(jQuery);
Note: See TracBrowser for help on using the repository browser.