首頁 > web前端 > js教程 > js 图片轮播(5张图片)_图象特效

js 图片轮播(5张图片)_图象特效

WBOY
發布: 2016-05-16 18:56:50
原創
1364 人瀏覽過

演示地址:http://img.jb51.net/online/picPlayer/picplay.htm

复制代码 代码如下:



    
        pic player
        
        
    
    
    
        

            there is a pic-player
        

        <script> <BR> var p = $('#picplayer'); <BR> var pics1 = [{url:'http://img.jb51.net/online/picPlayer/1.jpg',link:'http://www.jb51.net/#',time:5000},{url:'http://img.jb51.net/online/picPlayer/2.jpg',link:'http://www.jb51.net/#',time:4000},{url:'http://img.jb51.net/online/picPlayer/3.jpg',link:'http://www.jb51.net',time:6000},{url:'http://img.jb51.net/online/picPlayer/2.jpg',link:'http://www.jb51.net',time:6000},{url:'http://img.jb51.net/online/picPlayer/1.jpg',link:'http://www.jb51.net',time:6000}]; <BR> initPicPlayer(pics1,p.css('width').split('px')[0],p.css('height').split('px')[0]); <BR> // <BR> // <BR> function initPicPlayer(pics,w,h) <BR> { <BR> //选中的图片 <BR> var selectedItem; <BR> //选中的按钮 <BR> var selectedBtn; <BR> //自动播放的id <BR> var playID; <BR> //选中图片的索引 <BR> var selectedIndex; <BR> //容器 <BR> var p = $('#picplayer'); <BR> p.text(''); <BR> p.append('<div id="piccontent"></script>
');
                var c = $('#piccontent');
                for(var i=0;i                {
                    //添加图片到容器中
                    c.append('js 图片轮播(5张图片)_图象特效');
                }
                //按钮容器,绝对定位在右下角
                p.append('
');
                //
                var btnHolder = $('#picbtnHolder');
                btnHolder.append('
');
                var btns = $('#picbtns');
                //
                for(var i=0;i                {
                    //增加图片对应的按钮
                    btns.append(' '+(i+1)+'  ');
                    $('#picbtn'+i).data('index',i);
                    $('#picbtn'+i).click(
                        function(event)
                        {
                            if(selectedItem.attr('src') == $('#picitem'+$(this).data('index')).attr('src'))
                            {
                                return;
                            }
                            setSelectedItem($(this).data('index'));
                        }
                    );
                }
                btns.append(' ');
                ///
                setSelectedItem(0);
                //显示指定的图片index
                function setSelectedItem(index)
                {
                    selectedIndex = index;
                    clearInterval(playID);
                    //alert(index);
                    if(selectedItem)selectedItem.fadeOut('fast');
                    selectedItem = $('#picitem'+index);
                    selectedItem.fadeIn('slow');
                    //
                    if(selectedBtn)
                    {
                        selectedBtn.css('backgroundColor','#eee');
                        selectedBtn.css('color','#000');
                    }
                    selectedBtn = $('#picbtn'+index);
                    selectedBtn.css('backgroundColor','#000');
                    selectedBtn.css('color','#fff');
                    //自动播放
                    playID = setInterval(function()
                    {
                        var index = selectedIndex+1;
                        if(index > pics.length-1)index=0;
                        setSelectedItem(index);
                    },pics[index].time);
                }
            }

            

        

        
    


如果想增加图片可以通过增加 var pics1 后面的内容。即可。
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板