>  기사  >  웹 프론트엔드  >  js 그림 캐러셀(5개 그림)_이미지 특수 효과

js 그림 캐러셀(5개 그림)_이미지 특수 효과

WBOY
WBOY원래의
2016-05-16 18:56:501340검색

데모 주소: 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"></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>                     기능(이벤트) <br>               <br>                            if(selectedItem.attr('src') == $('#picitem' $(this) .data('index')).attr('src')) <br>                         { <br>                          반환;      } <br>                         setSelectedItem($(this).data('index')) <br> } <br>                    ); <br>                }<br>                btns.append(' '); <br>               /// <br>                setSelectedItem(0); <br>               //显示指정적 이미지 인덱스 <br>               함수 setSelectedItem(index) <br>               { = 색인; <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>                 { n.css('배경색상','#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>                         var index = selectedIndex 1; >                     setSelectedItem(index); <br>                 },pics[index].time); <br>               } <br>            } <br><br>             <br><br>        </script>

        
    



如果想增加图文可以过增加 var photos1 后面的内容。即可。
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.