• Js相册横向滚动效果


    来源:http://www.lanrentuku.com/lanren/code/20071129/code195932.shtml
      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>
      8body {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">
     54var browse = window.navigator.appName.toLowerCase();
     55var MyMar;
     56var speed = 1//速度,越大越慢
     57var spec = 1//每次滚动的间距, 越大滚动越快
     58var minOpa = 50//滤镜最小值
     59var maxOpa = 100//滤镜最大值
     60var spa = 2//缩略图区域补充数值
     61var w = 0;
     62spec = (browse.indexOf("microsoft"> -1? spec : ((browse.indexOf("opera"> -1? spec*10 : spec*20);
     63function $(e) {return document.getElementById(e);}
     64function goleft() {$('photos').scrollLeft -= spec;}
     65function goright() {$('photos').scrollLeft += spec;}
     66function 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);}
     79window.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>
    实际用的时候有点区别
  • 相关阅读:
    Codeforces 1105C Ayoub and Lost Array
    绍兴市acm竞赛
    CodeForces#520 div2 1062B
    CodeForces#520 div2 1062A
    1067A
    测试MathJax
    BZOJ1010 玩具装箱toy
    停止
    秽翼
    爆零
  • 原文地址:https://www.cnblogs.com/htht66/p/1157216.html
Copyright © 2020-2023  润新知