Home  >  Article  >  Web Front-end  >  js picture carousel (5 pictures)_image special effects

js picture carousel (5 pictures)_image special effects

WBOY
WBOYOriginal
2016-05-16 18:56:501341browse

Demo address: http://img.jb51.net/online/picPlayer/picplay.htm

Copy code The code is as follows:



    
        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"></div>'); <br>                var c = $('#piccontent'); <br>                for(var i=0;i<pics.length;i++) <BR> { <BR> //添加图片到容器中 <BR> c.append('<a href="'+pics[i].link+'" target="_blank"><img id="picitem'+i+'" style="display: none;z-index:'+i+'" src="'+pics[i].url+'" /></a>'); <br>                } <br>                //按钮容器,绝对定位在右下角 <br>                p.append('<div id="picbtnHolder" style="position:absolute;top:'+(h-25)+'px;width:'+w+'px;height:20px;z-index:10000;"></div>'); <br>                // <br>                var btnHolder = $('#picbtnHolder'); <br>                btnHolder.append('<div id="picbtns" style="float:right; padding-right:1px;"></div>'); <br>                var btns = $('#picbtns'); <br>                // <br>                for(var i=0;i<pics.length;i ) <BR>                { <BR>                    //增加图片对应的按钮 <BR>                    btns.append('<span id="picbtn' i '" style="cursor:pointer; border:solid 1px #ccc;background-color:#eee; display:inline-block;"> ' (i 1) ' </span> '); <br>                    $('#picbtn' i).data('index',i); <br>                    $('#picbtn' i).click( <br>                        function(event) <br>                        { <br>                            if(selectedItem.attr('src') == $('#picitem' $(this).data('index')).attr('src')) <br>                            { <br>                                return; <br>                            } <br>                            setSelectedItem($(this).data('index')); <br>                        } <br>                    ); <br>                }<br>                btns.append(' '); <br>                /// <br>                setSelectedItem(0); <br>                //显示指定的图片index <br>                function setSelectedItem(index) <br>                { <br>                    selectedIndex = index; <br>                    clearInterval(playID); <br>                    //alert(index); <br>                    if(selectedItem)selectedItem.fadeOut('fast'); <br>                    selectedItem = $('#picitem' index); <br>                    selectedItem.fadeIn('slow'); <br>                    // <br>                    if(selectedBtn) <br>                    { <br>                        selectedBtn.css('backgroundColor','#eee'); <br>                        selectedBtn.css('color','#000'); <br>                    } <br>                    selectedBtn = $('#picbtn' index); <br>                    selectedBtn.css('backgroundColor','#000'); <br>                    selectedBtn.css('color','#fff'); <br>                    //自动播放 <br>                    playID = setInterval(function() <br>                    { <br>                        var index = selectedIndex 1; <br>                        if(index > pics.length-1)index=0; <br>                        setSelectedItem(index); <br>                    },pics[index].time); <br>                } <br>            } <br><br>             <br><br>        </script>

        
    


如果想增加图片可以通过增加 var pics1 后面的内容。即可。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn