最近在做游戏宣传页面时,在展示MM图片时需要用到图片流动的代码,默认显示一定的图片,有上下/左右的方向,通过方向来控制没有显示的图片,整理出来,共需要的朋友借鉴下,点这里看演示:上下滚动或将如下代码复制另存网页格式查看效果.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.txt_1 {font:bold 24px Verdana, Tahoma;color:#fff}
img.thumb_img {cursor:pointer;display:block;margin-bottom:10px}
img#main_img {cursor:pointer;display:block; max-height:260px; max-width:300px; overflow:hidden; min-height:30px; min-width:30px;}
#gotop {cursor:pointer;display:block;}
#gobottom {cursor:pointer;display:block;}
#showArea {height:270px;margin:10px;overflow:hidden}
.info {color:#666;font:normal 9px Verdana;margin-top:20px}
.info a:link, .info a:visited {color:#666;text-decoration:none}
.info a:hover {color:#fff;text-decoration:none}
.li {border:2px double #ccc; padding:2px; margin:3px 0px;}
.big_photo{background:url(bigphoto_bg.jpg) 0px 0px no-repeat; border:2px double #ccc;width:328px;height:283px;padding-top:11px;padding-left:2px;overflow:hidden; margin-bottom:6px;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>纵向控制滚动图片代码-www.xianzheng.net.cn</title>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td width="640" align="center"><div class="big_photo_content">
<div class="big_photo"><img src="image/bigphoto.jpg" width="301" height="263" id="main_img" /> </div>
<div class="big_photo_ding">这里显示标题,<a href="/">点击回主页</a></div>
</div></td>
<td width="110" align="center" valign="top"><img src="image/gotop.gif" name="gotop" width="100" height="14" id="gotop" />
<div id="showArea"> <img src="image/bigphoto.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="image/bigphoto.jpg" link="http://www.xianzheng.net.cn/"/> <img src="upload/2009/1/200901141512203102.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512203102.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512211036.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512211036.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512222412.gif" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512222412.gif" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512236330.gif" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512236330.gif" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512237048.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512237048.jpg" link="http://www.xianzheng.net.cn/" /> <img src="http://www.hellofzl.cn/upimg/userup/9/0812/22202014943N_lit.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="http://www.xianzheng.net.cn//test/images/3.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512232216.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512232216.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512247643.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512247643.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512242252.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512242252.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512258801.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512258801.jpg" link="http://www.xianzheng.net.cn/" /> <img src="upload/2009/1/200901141512232216.jpg" alt="hugo'blog,梧桐树整理的JS代码" width="85" height="74" border="0" class="thumb_img li" rel="upload/2009/1/200901141512232216.jpg" link="http://www.xianzheng.net.cn/" /> </div>
<img src="image/gobottom2.gif" width="100" height="14" id="gobottom" /></td>
</tr>
</table>
<script language="javascript">
function $(e) {return document.getElementById(e);}
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}
var MyMar;
var speed = 1; //速度,越大越慢
var spec = 2; //每次滚动的间距, 越大滚动越快
var ipath = 'http://www.xianzheng.net.cn/upload/'; //图片路径
var thumbs = document.getElementsByClassName('thumb_img');
for (var i=0; i<thumbs.length; i++) {
thumbs[i].onmouseover = function () {$('main_img').src=this.rel; $('main_img').link=this.link;};
thumbs[i].onclick = function () {location = this.link}
}
$('main_img').onclick = function () {location = this.link;}
$('gotop').onmouseover = function() {this.src = ipath + 'gotop2.gif'; MyMar=setInterval(gotop,speed);}
$('gotop').onmouseout = function() {this.src = ipath + 'gotop.gif'; clearInterval(MyMar);}
$('gobottom').onmouseover = function() {this.src = ipath + 'gobottom2.gif'; MyMar=setInterval(gobottom,speed);}
$('gobottom').onmouseout = function() {this.src = ipath + 'gobottom.gif'; clearInterval(MyMar);}
function gotop() {$('showArea').scrollTop-=spec;}
function gobottom() {$('showArea').scrollTop+=spec;}
</script>
</body>
</html>
点这里看演示:上下滚动或将如下代码复制另存网页格式查看效果.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="Author" content="番茄红了" />
<title>JS相册效果-横向-www.xianzheng.net.cn</title>
<style>
body {background:#000;margin:0;font:12px Verdana;text-align:center;}
#tbody {width:650px;margin:50px auto;}
#mainbody {width:640px;margin:5px;border:1px solid #222;padding:1px}
#mainphoto {cursor:pointer;display:block;}
#goleft {float:left;clear:left;margin:6px 5px 0 3px;}
#goright {float:right;clear:right;margin:6px 3px 0 5px;}
#photos {width:610px;height:54px;line-height:54px;border:1px solid #222;margin:10px 0;overflow:hidden;}
#showArea img {display:block;float:left;margin:1px 0;cursor:pointer;border:1px solid #222}
</style>
</head>
<body>
<div id="tbody">
<div id="mainbody">
<img src="upload/2009/1/200901141547080250.gif" alt="hugo's blog,梧桐树" width="640" height="400" id="mainphoto" rel="http://www.hellofzl.com/images/5.jpg" name="http://www.xianzheng.net.cn/" />
</div>
<img src="http://www.hellofzl.com/images/goleft.gif" width="11" height="56" id="goleft" />
<img src="http://www.hellofzl.com/images/goright.gif" width="11" height="56" id="goright" />
<div id="photos">
<div id="showArea">
<!--
SRC: 缩略图地址
REL: 大图地址
NAME: 网址
-->
<img src="upload/2009/1/200901141547080250.gif" alt="hugo's blog,梧桐树" width="80" height="50" rel="upload/2009/1/200901141547080250.gif" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/4.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/4.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/5.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/5.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/3.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/3.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/4.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/4.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/5.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/5.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/3.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/3.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/4.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/4.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/5.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/5.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/3.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/3.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/4.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/4.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/5.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/5.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/3.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/3.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/4.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/4.jpg" name="http://www.xianzheng.net.cn/" />
<img src="http://www.hellofzl.com/images/5.jpg" alt="hugo's blog,梧桐树" width="80" height="50" rel="http://www.hellofzl.com/images/5.jpg" name="http://www.xianzheng.net.cn/" />
</div>
</div>
</div>
</body>
</html>
<script language="javascript" type="text/javascript">
var browse = window.navigator.appName.toLowerCase();
var MyMar;
var speed = 1; //速度,越大越慢
var spec = 1; //每次滚动的间距, 越大滚动越快
var minOpa = 50; //滤镜最小值
var maxOpa = 100; //滤镜最大值
var spa = 2; //缩略图区域补充数值
var w = 0;
spec = (browse.indexOf("microsoft") > -1) ? spec : ((browse.indexOf("opera") > -1) ? spec*10 : spec*20);
function $(e) {return document.getElementById(e);}
function goleft() {$('photos').scrollLeft -= spec;}
function goright() {$('photos').scrollLeft += spec;}
function setOpacity(e, n) {
if (browse.indexOf("microsoft") > -1) e.style.filter = 'alpha(opacity=' + n + ')';
else e.style.opacity = n/100;
}
$('goleft').style.cursor = 'pointer';
$('goright').style.cursor = 'pointer';
$('mainphoto').onmouseover = function() {setOpacity(this, maxOpa);}
$('mainphoto').onmouseout = function() {setOpacity(this, minOpa);}
$('mainphoto').onclick = function() {location = this.getAttribute('name');}
$('goleft').onmouseover = function() {this.src = 'http://www.hellofzl.com/images/goleft2.gif'; MyMar=setInterval(goleft, speed);}
$('goleft').onmouseout = function() {this.src = 'http://www.hellofzl.com/images/goleft.gif'; clearInterval(MyMar);}
$('goright').onmouseover = function() {this.src = 'http://www.hellofzl.com/images/goright2.gif'; MyMar=setInterval(goright,speed);}
$('goright').onmouseout = function() {this.src = 'http://www.hellofzl.com/images/goright.gif'; clearInterval(MyMar);}
window.onload = function() {
setOpacity($('mainphoto'), minOpa);
var rHtml = '';
var p = $('showArea').getElementsByTagName('img');
for (var i=0; i<p.length; i++) {
w += parseInt(p[i].getAttribute('width')) + spa;
setOpacity(p[i], minOpa);
p[i].onclick = function() {location = this.getAttribute('name');}
p[i].onmouseover = function() {
setOpacity(this, maxOpa);
$('mainphoto').src = this.getAttribute('rel');
$('mainphoto').setAttribute('name', this.getAttribute('name'));
setOpacity($('mainphoto'), maxOpa);
}
p[i].onmouseout = function() {
setOpacity(this, minOpa);
setOpacity($('mainphoto'), minOpa);
}
rHtml += '<img src="' + p[i].getAttribute('rel') + '" width="0" height="0" alt="" />';
}
$('showArea').style.width = parseInt(w) + 'px';
var rLoad = document.createElement("div");
$('photos').appendChild(rLoad);
rLoad.style.width = "1px";
rLoad.style.height = "1px";
rLoad.style.overflow = "hidden";
rLoad.innerHTML = rHtml;
}
</script>
订阅我的BLOG(RSS)