Heim  >  Artikel  >  Web-Frontend  >  js 图片轮播(5张图片)_图象特效

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

WBOY
WBOYOriginal
2016-05-16 18:56:501340Durchsuche

演示地址: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 后面的内容。即可。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn