1
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
2
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
3
<
head
>
4
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
/>
5
<
meta
name
="Author"
content
="懒人图库"
/>
6
<
title
>
横向的JS相册效果
</
title
>
7
<
style
>
8
body {
}{background:#000;margin:0;font:12px Verdana;text-align:center;}
9
#tbody {
}{width:650px;margin:20px auto;text-align:left;}
10
#mainbody {
}{width:640px;margin:5px;border:1px solid #222;padding:1px}
11
#mainphoto {
}{cursor:pointer;display:block;}
12
#goleft {
}{float:left;clear:left;margin:6px 5px 0 3px;}
13
#goright {
}{float:right;clear:right;margin:6px 3px 0 5px;}
14
#photos {
}{width:610px;height:54px;line-height:54px;border:1px solid #222;margin:10px 0;overflow:hidden;}
15
#showArea img {
}{display:block;float:left;margin:1px 0;cursor:pointer;border:1px solid #222}
16
.txt_1 {
}{font:bold 24px Verdana, Tahoma;color:#fff;}
17
</
style
>
18
</
head
>
19
<
body
>
20
<
div
id
="tbody"
><
span
class
="txt_1"
>
横向的JS相册效果
</
span
>
21
<
div
id
="mainbody"
>
22
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="640"
height
="400"
id
="mainphoto"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
23
</
div
>
24
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/goleft.gif"
width
="11"
height
="56"
id
="goleft"
/>
25
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/goright.gif"
width
="11"
height
="56"
id
="goright"
/>
26
<
div
id
="photos"
>
27
<
div
id
="showArea"
>
28
<!--
29
SRC: 缩略图地址
30
REL: 大图地址
31
NAME: 网址
32
-->
33
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
34
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
name
="http://www.makewing.com"
/>
35
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
36
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
37
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
name
="http://www.makewing.com"
/>
38
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
39
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
40
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
name
="http://www.makewing.com"
/>
41
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
42
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
43
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
name
="http://www.makewing.com"
/>
44
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
45
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
46
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/02.jpg"
name
="http://www.makewing.com"
/>
47
<
img
src
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
alt
="懒人图库"
width
="80"
height
="50"
rel
="http://download.makewing.com/lanren/code/jsphotobook/images/01.jpg"
name
="http://www.makewing.com"
/>
48
</
div
>
49
</
div
>
50
</
div
>
51
</
body
>
52
</
html
>
53
<
script
language
="javascript"
type
="text/javascript"
>
54
var browse = window.navigator.appName.toLowerCase();
55
var MyMar;
56
var speed = 1; //速度,越大越慢
57
var spec = 1; //每次滚动的间距, 越大滚动越快
58
var minOpa = 50; //滤镜最小值
59
var maxOpa = 100; //滤镜最大值
60
var spa = 2; //缩略图区域补充数值
61
var w = 0;
62
spec = (browse.indexOf("microsoft") > -1) ? spec : ((browse.indexOf("opera") > -1) ? spec*10 : spec*20);
63
function $(e)
{return document.getElementById(e);}
64
function goleft()
{$('photos').scrollLeft -= spec;}
65
function goright()
{$('photos').scrollLeft += spec;}
66
function setOpacity(e, n)
{
67
if (browse.indexOf("microsoft") > -1) e.style.filter = 'alpha(opacity=' + n + ')';
68
else e.style.opacity = n/100;
69
}
70
$('goleft').style.cursor = 'pointer';
71
$('goright').style.cursor = 'pointer';
72
$('mainphoto').onmouseover = function()
{setOpacity(this, maxOpa);}
73
$('mainphoto').onmouseout = function()
{setOpacity(this, minOpa);}
74
$('mainphoto').onclick = function()
{location = this.getAttribute('name');}
75
$('goleft').onmouseover = function()
{this.src = 'http://download.makewing.com/lanren/code/jsphotobook/images/goleft2.gif'; MyMar=setInterval(goleft, speed);}
76
$('goleft').onmouseout = function()
{this.src = 'http://download.makewing.com/lanren/code/jsphotobook/images/goleft.gif'; clearInterval(MyMar);}
77
$('goright').onmouseover = function()
{this.src = 'http://download.makewing.com/lanren/code/jsphotobook/images/goright2.gif'; MyMar=setInterval(goright,speed);}
78
$('goright').onmouseout = function()
{this.src = 'http://download.makewing.com/lanren/code/jsphotobook/images/goright.gif'; clearInterval(MyMar);}
79
window.onload = function()
{
80
setOpacity($('mainphoto'), minOpa);
81
var rHtml = '';
82
var p = $('showArea').getElementsByTagName('img');
83
for (var i=0; i<p.length; i++)
{
84
w += parseInt(p[i].getAttribute('width')) + spa;
85
setOpacity(p[i], minOpa);
86
p[i].onclick = function()
{location = this.getAttribute('name');}
87
p[i].onmouseover = function()
{
88
setOpacity(this, maxOpa);
89
$('mainphoto').src = this.getAttribute('rel');
90
$('mainphoto').setAttribute('name', this.getAttribute('name'));
91
setOpacity($('mainphoto'), maxOpa);
92
}
93
p[i].onmouseout = function()
{
94
setOpacity(this, minOpa);
95
setOpacity($('mainphoto'), minOpa);
96
}
97
rHtml += '<img src="' + p[i].getAttribute('rel') + '" width="0" height="0" alt="" />';
98
}
99
$('showArea').style.width = parseInt(w) + 'px';
100
var rLoad = document.createElement("div");
101
$('photos').appendChild(rLoad);
102
rLoad.style.width = "1px";
103
rLoad.style.height = "1px";
104
rLoad.style.overflow = "hidden";
105
rLoad.innerHTML = rHtml;
106
}
107
</
script
>
实际用的时候有点区别

2

3

4

5

6

7



8



9



10



11



12



13



14



15



16



17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53



54

55

56

57

58

59

60

61

62

63



64



65



66



67

68

69

70

71

72



73



74



75



76



77



78



79



80

81

82

83



84

85

86



87



88

89

90

91

92

93



94

95

96

97

98

99

100

101

102

103

104

105

106

107
