JS技术

Javascript控制图片滚动的效果_Javascript教程

字号+ 作者:H5之家 来源:H5之家 2015-09-26 13:05 我要评论( )

Javascript控制图片滚动的效果,学习Javascript控制图片滚动的效果,Javascript控制图片滚动的效果,查看Javascript控制图片滚动的效果,纵向的,写的第一个版本,没

纵向的,写的第一个版本,没加滤镜
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="Author" content="番茄红了" />
<title>JS相册效果 -- 纵向</title>
<style>
body {background:#000000;margin:20px 0;font:12px Verdana, Arial, Tahoma;text-align:center;vertical-align:middle;color:#FFFFFF}
img {border:none}
.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;}
#gotop {cursor:pointer;display:block;}
#gobottom {cursor:pointer;display:block;}
#showArea {height:355px;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}
</style>
</head>
<body>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="5">
  <tr>
    <td height="75" colspan="2" align="left" class="txt_1">JS相册效果</td>
  </tr>
  <tr>
    <td width="640" align="center"><img src="" alt="番茄红了..." width="640" height="400" border="0" id="main_img" rel="" link="" /></td>
    <td width="110" align="center" valign="top">
    <img src="" width="100" height="14" id="gotop" />
    <div id="showArea">
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
        <img src="" alt="番茄红了..." width="80" height="50" border="0" class="thumb_img" rel="" link="" />
    </div>
    <img src="" width="100" height="14" id="gobottom" /></td>
  </tr>
</table>
<center class="info"><a href="" title="番茄's Blog"></a>&nbsp;&nbsp;|&nbsp;&nbsp;Akon&nbsp;By&nbsp;2006/12/26</center>
</body>
</html>
<script language="javascript" type="text/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 = 1; //每次滚动的间距, 越大滚动越快
var ipath = 'http://www.tblog.com.cn/test/images/'; //图片路径
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>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • JavaScript入门教程(二)_javascript教程教程

    JavaScript入门教程(二)_javascript教程教程

    2015-10-10 14:25

  • JavaScript入门教程(五)_javascript教程教程

    JavaScript入门教程(五)_javascript教程教程

    2015-10-10 14:21

  • JavaScript入门教程(四)_javascript教程教程

    JavaScript入门教程(四)_javascript教程教程

    2015-10-10 14:19

  • JavaScript入门教程(三)_javascript教程教程

    JavaScript入门教程(三)_javascript教程教程

    2015-10-10 14:17

网友点评