imgslideshow: 基于 jQuery 的图片幻灯片插件

第一、jQury幻灯片JS代码

$(document).ready(function(){
       qinglong()
});

 

function qinglong(){
     $.fn.extend({
        'imgSlideShow': function(options){
            // 扩展参数
            var op = $.extend({
                'itemclass': null,
                'desclass': null,
                'delay': 2000
            }, options);
          

            // 设置图片项的样式
            this.children('.' + op.itemclass).css({
                clear: 'both',
                display: 'none'
            });
            // 添加数字标签项窗口
            $('<div id="imgslideshow_label0000"></div>').appendTo(this).css({
                position: 'absolute',
                bottom: '2px',
                right: '2px',
                width: '100%',
                height: '22px',
                'z-index': 10000,
                overflow: 'hidden'
            });
            // 取得所有图片项
            var items = $('.' + op.itemclass, this);
            // 图片项的数目
            var itemsLength = items.length;
            // 当前的图片项索引
            var curItemIndex = 0;
            // 当前的 timeout 函数返回值
            var timeoutReturn;

            // 添加数字标签项
            for(var i=itemsLength-1;i>=0;i--){
                $('<div class="label0000" id="label0000' + i + '">' + (i + 1) + '</div>').appendTo('#imgslideshow_label0000').css({
                    'float': 'right',
                   'width': '20px',
                    'height': '20px',
                    'line-height': '20px',
                    'text-align': 'center',
                    'font-weight': 'bold',
                    'background-color': '#EFEBD6',
                    'opacity': 0.8,
                    'border': '1px solid #000',
                    'cursor': 'pointer',
                    'margin-left': '2px'
                    // 标签项的单击事件
                }).click(function(e){
                    // 停止当前的图片项动画并将其隐藏和设置回透明度为1
                    items.eq(curItemIndex).stop().hide().css({
                        opacity: 1
                    });
                    // 阻止事件流
                    e.stopPropagation();
                    // 暂停当前的 timeout 函数
                    clearTimeout(timeoutReturn);
                    // 设置标签项的样式
                    $('#label0000' + curItemIndex).css('background-color', '#EFEBD6');
                    items.eq(curItemIndex).hide();
                    $('#label0000' + curItemIndex).css('background-color', '#EFEBD6');
                    // 从当前的索引开始,重新开始图片动画
                    curItemIndex = parseInt($(this).text()) - 1;
                    imgSlideShowProcess();
                });
            }
            // 图片动画执行函数
            var imgSlideShowProcess = function(){
                $('#label0000' + curItemIndex).css('background-color', '#FF8210');
                items.eq(curItemIndex).fadeIn(300, function(){
                    timeoutReturn = setTimeout(imgFadeOut, op.delay);
                });
            };
            // 淡出图片
            var imgFadeOut = function(){
                items.eq(curItemIndex).fadeOut(1, function(){
                    $('#label0000' + curItemIndex).css('background-color', '#EFEBD6');
                    curItemIndex = (curItemIndex + 1) % itemsLength;
                    imgSlideShowProcess();
                });
            };
            // 开始图片动画
            imgSlideShowProcess();

            return this;
        }
    });
}

 

第二、html页面代码

<html>

<head>

<script type="text/javascript" src="/../slider.js"></script><!--此处是jQury幻灯联接插件路径-->

<script type="text/javascript" src="/../jqury.js"></script><!--此处是jQury联接插件路径-->

 <script type="text/javascript">
                $(function(){
                    $('#con').imgSlideShow({itemclass: 'item', 'delay': 3000})
                });
        
            </script>

</head>

<body>

<div id="con">
                   <div class="item">
                       <a href="">
                            <img src="/slider-img/1.jpg"/>
                       </a>

                   </div>
                   <div class="item">
                       <a href="">
                            <img src="/slider-img/2.jpg"/>
                       </a>
                   </div>
                   <div class="item">
                       <a href="">
                            <img src="/slider-img/3.jpg"/>
                       </a>
                   </div>
                   <div class="item">
                       <a href="">
                            <img src="/slider-img/4.jpg"/>
                       </a>
                   </div>
                   <div class="item">
                        <a href="">
                            <img src="/slider-img/5.jpg"/>
                       </a>
                   </div>
               </div>

</body>

</html>

 

备注:原载地址http://mrwlwan.wordpress.com/2008/12/11/imgslideshow-%E5%9F%BA%E4%BA%8E-jquery-%E7%9A%84%E5%9B%BE%E7%89%87%E5%B9%BB%E7%81%AF%E7%89%87%E6%8F%92%E4%BB%B6/   

我只是捎作了一修改

你可能感兴趣的:(jquery,function,null,Class,div,delay)