Maison > interface Web > js tutoriel > le corps du texte

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

WBOY
Libérer: 2016-05-16 18:56:50
original
1303 Les gens l'ont consulté

演示地址: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 后面的内容。即可。
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!