• 放大效果
HTML
1 <img src="cricci.jpg" alt="Muse: Christina Ricci" big="cricci-large.jpg" id="ricci" />
JavaScript
1 window.addEvent('domready',function() {
2 new Zoomer('ricci',{
3 smooth: 10/*,
4 big: 'cricci-large.jpg' */
5 });
6 });
7
Demo
• 缩略图+文字
HTML
代码
1 <div id="slideshow-container">
2 <img src="slideshow/cricci1.jpg" alt="Christina Ricci 1::This is the caption for photo 1.">
3 <img src="slideshow/cricci2.jpg" alt="Christina Ricci 2::This is the caption for photo 2.">
4 <img src="slideshow/cricci3.jpg" alt="Christina Ricci 3::This is the caption for photo 3.">
5 <img src="slideshow/cricci4.jpg" alt="Christina Ricci 4::This is the caption for photo 4.">
6 <img src="slideshow/cricci5.jpg" alt="Christina Ricci 5::This is the caption for photo 5.">
7 </div>
CSS
代码
1 #slideshow-container { width:512px; height:384px; position:relative; }
2 #slideshow-container img { width:512px; height:384px; display:block; position:absolute; top:0; left:0; z-index:1; }
3 #slideshow-container-controls { margin:10px 0 0 0; }
4 #slideshow-container-controls img { cursor:pointer; width:100px; height:75px; border:1px solid #ccc; float:left; margin:0 1px 0 0; }
5 #slideshow-container-caption { height:70px; position:absolute; bottom:0; left:0; right:0; background:#000; z-index:10; overflow:hidden; }
6 * html #slideshow-container-caption { width:100%; }
7 #slideshow-container-caption h3 { font-size:24px; font-weight:bold; color:#fff; padding:10px 10px 3px 10px; }
8 #slideshow-container-caption p { color:#eee; font-size:11px; padding:0 10px 10px 10px; }
9 .toc-active { border-color:#000; }
JavaScript
代码
1 window.addEvent('domready',function() {
2 /* settings */
3 var showDuration = 5000;
4 var container = $('slideshow-container');
5 var images = container.getElements('img');
6 var currentIndex = 0;
7 var interval;
8 var toc = [];
9 var tocActive = 'toc-active';
10 var thumbOpacity = 0.7;
11
12 /* new: create caption area */
13 var captionDIV = new Element('div',{
14 id: 'slideshow-container-caption',
15 styles: {
16 //display:none,
17 opacity: thumbOpacity
18 }
19 }).inject(container);
20 var captionHeight = captionDIV.getSize().y;
21 captionDIV.setStyle('height',0);
22
23 /* new: starts the show */
24 var start = function() { interval = show.periodical(showDuration); };
25 var stop = function() { $clear(interval); };
26 /* worker */
27 var show = function(to) {
28 images[currentIndex].fade('out');
29 toc[currentIndex].removeClass(tocActive).fade(thumbOpacity);
30 images[currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : 0))].fade('in');
31 toc[currentIndex].addClass(tocActive).fade(1);
32 captionDIV.set('tween',{
33 onComplete: function() {
34 captionDIV.set('tween',{
35 onComplete: $empty
36 }).tween('height',captionHeight);
37 /* parse caption */
38 var title = '';
39 var captionText = '';
40 if(images[currentIndex].get('alt')) {
41 cap = images[currentIndex].get('alt').split('::');
42 title = cap[0];
43 captionText = cap[1];
44 captionDIV.set('html','<h3>' + title + '</h3>' + (captionText ? '<p>' + captionText + '</p>' : ''));
45 }
46 }
47 }).tween('height',0);
48 };
49
50 /* new: create preview area */
51 var preview = new Element('div',{
52 id: 'slideshow-container-controls'
53 }).inject(container,'after');
54
55 /* new: control: table of contents */
56 images.each(function(img,i){
57 /* add to table of contents */
58 toc.push(new Element('img',{
59 src: img.get('src'),
60 title: img.get('alt'),
61 styles: {
62 opacity: thumbOpacity
63 },
64 events: {
65 click: function(e) {
66 if(e) e.stop();
67 stop();
68 show(i);
69 start();
70 },
71 mouseenter: function() {
72 this.fade(1);
73 },
74 mouseleave: function() {
75 if(!this.hasClass(tocActive)) this.fade(thumbOpacity);
76 }
77 }
78 }).inject(preview));
79 if(i > 0) { img.set('opacity',0); }
80
81 });
82
83 /* control: start/stop on mouseover/mouseout */
84 container.addEvents({
85 mouseenter: function() { stop(); },
86 mouseleave: function() { start(); }
87 });
88
89 /* start once the page is finished loading */
90 window.addEvent('load',function(){ show(0); start(); });
91 });
Demo
• 简单幻灯
HTML
代码
1 #slideshow-holder { width:600px; height:400px; background:url(spinner.gif) center center no-repeat #fff; position:relative; }
2 #progress { position:absolute; width:100%; text-align:center; color:#999; top:225px; }
3
CSS
代码
#slideshow-holder { width:600px; height:400px; background:url(spinner.gif) center center no-repeat #fff; position:relative; }
#progress { position:absolute; width:100%; text-align:center; color:#999; top:225px; }
JavaScript
代码
1 window.addEvent('domready',function() {
2 /* preloading */
3 var imagesDir = 'epics/';
4 var images = ['2.jpg','3.jpg','1.jpg','4.jpg','5.jpg'];
5 var holder = $('slideshow-holder');
6 images.each(function(img,i){ images[i] = imagesDir + '' + img; }); //add dir to images
7 var progressTemplate = 'Loading image {x} of ' + images.length;
8 var updateProgress = function(num) {
9 progress.set('text',progressTemplate.replace('{x}',num));
10 };
11 var progress = $('progress');
12 updateProgress('text','0');
13 var loader = new Asset.images(images, {
14 onProgress: function(c,index) {
15 updateProgress('text',index + 1);
16 },
17 onComplete: function() {
18 var slides = [];
19 /* put images into page */
20 images.each(function(im) {
21 slides.push(new Element('img',{
22 src:im,
23 width: 600,
24 height: 400,
25 styles: {
26 opacity:0,
27 top:0,
28 left:0,
29 position:'absolute',
30 'z-index': 10
31 }
32 }).inject(holder));
33 holder.setStyle('background','url(logo.png) center 80px no-repeat');
34 });
35 var showInterval = 5000;
36 var index = 0;
37 progress.set('text','Images loaded. MooTools FTW.');
38 (function() {slides[index].tween('opacity',1); }).delay(1000);
39 var start = function() {
40 (function() {
41 holder.setStyle('background','');
42 slides[index].fade(0);
43 ++index;
44 index = (slides[index] ? index : 0);
45 slides[index].fade(1);
46 }).periodical(showInterval);
47 };
48
49 /* start the show */
50 start();
51 }
52 });
53 });
54
Demo
代码
1 window.addEvent('domready',function() {
2 /* preloading */
3 var imagesDir = 'epics/';
4 var images = ['2.jpg','3.jpg','1.jpg','4.jpg','5.jpg'];
5 var holder = $('slideshow-holder');
6 images.each(function(img,i){ images[i] = imagesDir + '' + img; }); //add dir to images
7 var progressTemplate = 'Loading image {x} of ' + images.length;
8 var updateProgress = function(num) {
9 progress.set('text',progressTemplate.replace('{x}',num));
10 };
11 var progress = $('progress');
12 updateProgress('text','0');
13 var loader = new Asset.images(images, {
14 onProgress: function(c,index) {
15 updateProgress('text',index + 1);
16 },
17 onComplete: function() {
18 var slides = [];
19 /* put images into page */
20 images.each(function(im) {
21 slides.push(new Element('img',{
22 src:im,
23 width: 600,
24 height: 400,
25 styles: {
26 opacity:0,
27 top:0,
28 left:0,
29 position:'absolute',
30 'z-index': 10
31 }
32 }).inject(holder));
33 holder.setStyle('background','url(logo.png) center 80px no-repeat');
34 });
35 var showInterval = 5000;
36 var index = 0;
37 progress.set('text','Images loaded. MooTools FTW.');
38 (function() {slides[index].tween('opacity',1); }).delay(1000);
39 var start = function() {
40 (function() {
41 holder.setStyle('background','');
42 slides[index].fade(0);
43 ++index;
44 index = (slides[index] ? index : 0);
45 slides[index].fade(1);
46 }).periodical(showInterval);
47 };
48
49 /* start the show */
50 start();
51 }
52 });
53 });
54


浙公网安备 33010602011771号