最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP技巧:图片之间的切换

日期:09-07    来源:中国设计秀    作者:cnwebshow.com

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">Y8j中国设计秀
<html xmlns="http://www.w3.org/1999/xhtml">Y8j中国设计秀
<head>Y8j中国设计秀
  <title> RevealTrans </title>Y8j中国设计秀
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Y8j中国设计秀
  <style>Y8j中国设计秀
    body{background-color: #CCCCCC;}Y8j中国设计秀
    #container {width: 525px;text-align: center;margin: 0 auto;}    Y8j中国设计秀
    #context {background-color: #777777;border: 2px solid #555555;width: 500px;}    Y8j中国设计秀
    #context img {border: none;margin: 0px;}    Y8j中国设计秀
    #nav {width: 510px;height: 140px;overflow: hidden;list-style: none;margin-top: 3px;position: relative;    padding-left: 0px; margin-left:3px}    Y8j中国设计秀
    #nav li {float: left; margin: 0 7px 4px 0;border: 2px solid #555;}    Y8j中国设计秀
    #nav div {width: 90px;height: 60px; overflow: hidden;}    Y8j中国设计秀
    #nav div img {width: 95px;height: 60px;}Y8j中国设计秀
  </style>Y8j中国设计秀
  <script>Y8j中国设计秀
    /*!Y8j中国设计秀
     *    RevealTransY8j中国设计秀
     *    http://www.cnblogs.com/goodness2010/Y8j中国设计秀
     *Y8j中国设计秀
     *  Copyright (c) 2009 GoodNess2010Y8j中国设计秀
     *  Date: 2009-1-13 (星期三)Y8j中国设计秀
     */Y8j中国设计秀
    var $ = function(id) { return document.getElementById(id) };Y8j中国设计秀
    var isIE = navigator.userAgent.indexOf('MSIE') != -1 ? true : false;Y8j中国设计秀
    var $extend = function(a, b) { for(var c in b) { a[c] = b[c]; } return a; };Y8j中国设计秀
    var forEach = function(array, callback, thisp) {Y8j中国设计秀
        if(array.forEach){ Y8j中国设计秀
            array.forEach(callback, thisp);Y8j中国设计秀
        }else {Y8j中国设计秀
            for(var i = 0, len = array.length; i < len; i++) {Y8j中国设计秀
                if(i in array) callback.call(thisp, array[i], i, array);Y8j中国设计秀
            }Y8j中国设计秀
        }Y8j中国设计秀
    };Y8j中国设计秀
    var RevealTrans = function(cId, options) {Y8j中国设计秀
        this.cId = cId;Y8j中国设计秀
        this.timer = null;Y8j中国设计秀
        this.curImg = null;Y8j中国设计秀
        this.index = 1;Y8j中国设计秀
        $extend(this, this.setOptions(options));Y8j中国设计秀
        this.init();Y8j中国设计秀
    };Y8j中国设计秀
Y8j中国设计秀
    RevealTrans.PRototype = {Y8j中国设计秀
        constructor: RevealTrans,Y8j中国设计秀
        // 初始化函数Y8j中国设计秀
        init: function() {Y8j中国设计秀
            this.createStruct();Y8j中国设计秀
            this.bindEvents();Y8j中国设计秀
        },Y8j中国设计秀
        // 设置默认参数Y8j中国设计秀
        setOptions: function(options) {Y8j中国设计秀
            this.options = {Y8j中国设计秀
                auto: true,            // 是否自动切换Y8j中国设计秀
                transition: 23,        // 滤镜参数(详见说明)Y8j中国设计秀
                duration: 1.5,         // 滤镜转换所用时间(单位为秒)Y8j中国设计秀
                minOpa: 40,            // 导航图片的初始透明度Y8j中国设计秀
                maxOpa: 100,           // 导航图片的最终透明度Y8j中国设计秀
                pause: 2000,           // 自动切换间隔时间Y8j中国设计秀
                coll: [],              // 图片集合Y8j中国设计秀
                onEnd: function(){}    // 图片滤镜转换结束自定义函数Y8j中国设计秀
            };Y8j中国设计秀
            return $extend(this.options, options || {});Y8j中国设计秀
        },Y8j中国设计秀
        // 生成HTML结构Y8j中国设计秀
        createStruct: function() {Y8j中国设计秀
            var _html = '', _this = this;Y8j中国设计秀
            forEach(this.coll, function(O) {Y8j中国设计秀
                _html += '<li><div><img src = ' + O + '></div></li>';Y8j中国设计秀
            });Y8j中国设计秀
            $(this.cId).innerHTML = _html;Y8j中国设计秀
            $('context').innerHTML = '<img src=' + this.coll[0] + '>';Y8j中国设计秀
            this.bindEvents();Y8j中国设计秀
        },Y8j中国设计秀
        // 设置透明度Y8j中国设计秀
        setOpacity: function(O, opacity) {Y8j中国设计秀
            if(!!isIE) O.style.filter = "alpha(opacity=" + opacity + ")";Y8j中国设计秀
            else O.style.opacity = opacity / 100;Y8j中国设计秀
        },Y8j中国设计秀
        // 绑定相关事件Y8j中国设计秀
        bindEvents: function() {Y8j中国设计秀
            var imgs = $(this.cId).getElementsByTagName('img'), _this = this;Y8j中国设计秀
            forEach(imgs, function(O, index) {Y8j中国设计秀
                index > 0 ? _this.setOpacity(O, _this.minOpa) : _this.curImg = O;Y8j中国设计秀
                O.onmouseover = function() { this.style.cursor = 'pointer'; };Y8j中国设计秀
                O._index = index;Y8j中国设计秀
                O.onclick = function() { _this.onStart(this); _this.index = this._index;};Y8j中国设计秀
            });Y8j中国设计秀
            // 默认演示第一个图片Y8j中国设计秀
            this.onStart(imgs[0]);Y8j中国设计秀
        },Y8j中国设计秀
        // 开始滤镜切换Y8j中国设计秀
        onStart: function(O) {Y8j中国设计秀
            var _this = this, context = $('context').getElementsByTagName('img')[0];Y8j中国设计秀
            _this.onStop();Y8j中国设计秀
            _this.setOpacity(_this.curImg, _this.minOpa);_this.setOpacity(O, _this.maxOpa); Y8j中国设计秀
            _this.curImg = O;Y8j中国设计秀
            if(isIE) {Y8j中国设计秀
                context.style.filter = "revealTrans()";Y8j中国设计秀
                _this.transFx(context);                     Y8j中国设计秀
            }Y8j中国设计秀
            context.setAttribute('src', O.getAttribute('src'));    Y8j中国设计秀
            // 判断是否自动切换Y8j中国设计秀
            if(!!this.auto) {Y8j中国设计秀
                var len = this.coll.length;Y8j中国设计秀
                _this.timer = setTimeout(function(){Y8j中国设计秀
                    _this.index < len ? _this.index++ : _this.index = 1;Y8j中国设计秀
                    _this.onStart($(_this.cId).getElementsByTagName('img')[_this.index - 1]);Y8j中国设计秀
                }, this.pause);Y8j中国设计秀
            }Y8j中国设计秀
        },Y8j中国设计秀
        // 滤镜演示Y8j中国设计秀
        transFx: function(O) {Y8j中国设计秀
            with(O.filters.revealTrans) {Y8j中国设计秀
                Transition = parseInt(this.transition, 10); Duration = parseFloat(this.duration); apply(); play();Y8j中国设计秀
            }Y8j中国设计秀
        },Y8j中国设计秀
        // 清除时间戳Y8j中国设计秀
        onStop: function() {Y8j中国设计秀
            clearInterval(this.timer);Y8j中国设计秀
        }Y8j中国设计秀
    };Y8j中国设计秀
  </script>Y8j中国设计秀
</head>Y8j中国设计秀
Y8j中国设计秀
<body>Y8j中国设计秀
      <div id="container">Y8j中国设计秀
          <div id="context"></div>Y8j中国设计秀
          <ul id="nav"></ul>Y8j中国设计秀
     </div>Y8j中国设计秀
    <script>Y8j中国设计秀
        var revealTrans = new RevealTrans('nav', {coll:['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg']});Y8j中国设计秀
    </script>Y8j中国设计秀
</body>Y8j中国设计秀
</html>Y8j中国设计秀
Y8j中国设计秀
Y8j中国设计秀
Y8j中国设计秀
[文字说明]Y8j中国设计秀
Y8j中国设计秀
图片切换:主要通过更改图片的链接.切换相应的图片. 如果设置了自动切换.就自动控制索引,如果达到最大值就重置为0.Y8j中国设计秀
Y8j中国设计秀
透明度设置: 这个也很简单.只要区别IE和其他浏览器的opacity就可以了.Y8j中国设计秀
Y8j中国设计秀
滤镜设置:Y8j中国设计秀
Y8j中国设计秀
RevealTrans是IE下的滤镜.很可惜在FF等不支持滤镜的浏览器会失去效果.(如果需要跨浏览器的这种效果可以考虑Flash).Y8j中国设计秀
Y8j中国设计秀
RevealTrans滤镜设置步骤:Y8j中国设计秀
Y8j中国设计秀
1.context.style.filter = "revealTrans()"; // 将图片filter属性设置为revealTrans();Y8j中国设计秀
2.Y8j中国设计秀
with(O.filters.revealTrans) {Y8j中国设计秀
    Transition = parseInt(this.transition, 10);  // 设置转换参数Y8j中国设计秀
    Duration = parseFloat(this.duration);        // 设置转换时间Y8j中国设计秀
    apply(); play();                             // 设置滤镜并执行Y8j中国设计秀
}Y8j中国设计秀
Y8j中国设计秀
Y8j中国设计秀
其中Transition参数说明如下:Y8j中国设计秀
Y8j中国设计秀
transition  :  可选项。整数值(Integer)。设置或检索转换所使用的方式。 0  :  矩形收缩转换。 Y8j中国设计秀
1  :  矩形扩张转换。 Y8j中国设计秀
2  :  圆形收缩转换。 Y8j中国设计秀
3  :  圆形扩张转换。 Y8j中国设计秀
4  :  向上擦除。 Y8j中国设计秀
5  :  向下擦除。 Y8j中国设计秀
6  :  向右擦除。 Y8j中国设计秀
7  :  向左擦除。 Y8j中国设计秀
8  :  纵向百叶窗转换。 Y8j中国设计秀
9  :  横向百叶窗转换。 Y8j中国设计秀
10  :  国际象棋棋盘横向转换。 Y8j中国设计秀
11  :  国际象棋棋盘纵向转换。 Y8j中国设计秀
12  :  随机杂点干扰转换。 Y8j中国设计秀
13  :  左右关门效果转换。 Y8j中国设计秀
14  :  左右开门效果转换。 Y8j中国设计秀
15  :  上下关门效果转换。 Y8j中国设计秀
16  :  上下开门效果转换。 Y8j中国设计秀
17  :  从右上角到左下角的锯齿边覆盖效果转换。 Y8j中国设计秀
18  :  从右下角到左上角的锯齿边覆盖效果转换。 Y8j中国设计秀
19  :  从左上角到右下角的锯齿边覆盖效果转换。 Y8j中国设计秀
20  :  从左下角到右上角的锯齿边覆盖效果转换。 Y8j中国设计秀
21  :  随机横线条转换。 Y8j中国设计秀
22  :  随机竖线条转换。 Y8j中国设计秀
23  :  随机使用上面可能的值转换 Y8j中国设计秀
Y8j中国设计秀
共有24种滤镜.其中23比较特殊可以随机样式.这里我默认使用的就是随机的.大家也可以根据自己的爱好去设置.Y8j中国设计秀
Y8j中国设计秀
Duration参数:Y8j中国设计秀
Y8j中国设计秀
duration  :  可选项。浮点数(Real)。设置或检索转换完成所用的时间。其值为秒.毫秒(0.0000)格式Y8j中国设计秀
Y8j中国设计秀
[代码使用]Y8j中国设计秀
Y8j中国设计秀
new RevealTrans('nav', {coll:['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg']});Y8j中国设计秀
Y8j中国设计秀
Y8j中国设计秀
其中第二项{}的设置可以对照我的setOptions的

本文引用地址:/bc/article_46148.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明