Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <ul>
    <li id="header">
      <div id="tit" class="left">TWITCH STREAMERS</div>
      <div class="choose right">
        <ul>
          <li>ALL</li>
          <li>ONLINE</li>
          <li>OFFLIINE</li>
        </ul>
      </div>
    </li>
    <li id="display"></li>
    <li></li>
  </ul>
</div>
              
            
!

CSS

              
                /*//公共样式*/
body,div,ul,li,p,img{
				margin:0px;
				padding:0px;
			}
li,ul{
	list-style: none;
}
body{
	font-family: 'Droid Serif';
}
.left{
	float:left;
}
.right{
	float:right;
}
/*除display区域外的样式*/
.container{
	margin:0 auto;
}
.container>ul>li,.container{
	width:600px;
}
.container>ul>li{
	margin-bottom: 5px;
}
.container>ul>li#header{
	height:100px;
	background:#7197a9;
}
.container>ul>li#header #tit{
	color:#cec8c8;
	font-size:30px;
	font-weight: bold;
	line-height: 100px;
	margin-left:20px;
}
.container>ul>li#header .choose{
	font-size:12px;
}
.container>ul>li#header .choose ul{
	margin-top:10px;
}
.container>ul>li#header .choose li{
	text-align: center;
	width:62px;
	height:20px;
	line-height: 20px;
	margin-bottom: 3px;
	border-radius:3px;
	background:#cec8c8;
	font-weight:bold;
	font-size:12px;
}
body > div > ul > li:nth-child(3){
	height:10px;
	background:#7197a9;
}
/*display区域*/
#display > div.online{
	background:#bed2c6;
	margin-bottom:5px;
}
#display > div.online a{
	color:#e2a980; 
}
#display > div.offline{
	background:#e2a980; 
	margin-bottom:5px;
}
#display > div.offline a{
	color:#bed2c6;
}
#header > div.choose.right > ul > li{
	cursor:pointer;
}
#display .all:after{
	content: '';
	display: block;
	clear:both;
}
#display .all div{
	float:left;
	margin-right:30px;
}
#display > div .imgBox{
	margin:7px;
}
#display img{
	width:60px;
	height:60px;
	border-radius:50%;
	border:3px solid white;
}
#display a{
	line-height:84px;
	text-decoration: none;
}
#display a:hover{
	text-decoration:underline;
}
#display > div .link{
	margin-left:20px;
	width:110px;
	text-align:center;
}
#display .des{
	width:300px;
	height:80px;
	overflow: hidden;
	line-height:80px;
	text-overflow: ellipsis;
	white-space:nowrap;
}
              
            
!

JS

              
                var urlId = ["45877376","79776140","30816637"];//分别是三个频道的频道号
function getChannels(){
	//make不同url,分别用于查询频道状态和查询频道相关信息
	function makeUrl(type,id){
		return 'https://api.twitch.tv/kraken/' + type + '/' + id;
	};
	for(let i in urlId){//这里如果不使用let,下面的ajax请求都是异步执行的,使用的i值有可能都为2
		//查看频道状态-是否开播
		$.ajax({
			type:"get",
			url:makeUrl('streams',urlId[i]),
			datatype:'JSONP',
			headers:{
					'Accept': 'application/vnd.twitchtv.v5+json',
					'Client-ID': 'zqe68al1fduevoswjw5slnayxxxqo9'
				},
			success:function(data){
				if(data.stream == null){
					var status = false;
				}else{
					var status = true;
				};
				//查询频道相关信息
				$.ajax({
					type:"get",
					url:makeUrl('channels',urlId[i]),
					headers:{
							'Accept': 'application/vnd.twitchtv.v5+json',
							'Client-ID': 'zqe68al1fduevoswjw5slnayxxxqo9'
						},
					datatype:'JSONP',
					success:function(data){
						var statusStr = (status)?'online':'offline';
						var html = '<div class="all '+ statusStr +'"><div class="imgBox"><img src="'+ data.logo +'" /></div><div class="link"><a target="_blank" href="'+ data.url +'">'+ data.name +'</a></div><div><p class="des">'+ data.description +'</p></div></div>';
						statusStr == 'online' ? $("#display").prepend(html) : $("#display").append(html);
					}
				});
			}
		});
	};
};
//设置三个按钮的点击事件
$(function(){
  getChannels();
  $('#header > div.choose.right > ul > li:nth-child(1)').click(function(){
    $('#display > div.all').show();
  });
  $('#header > div.choose.right > ul > li:nth-child(2)').click(function(){
    $('#display > div.all').hide();
    $('#display > div.online').show();
  });
  $('#header > div.choose.right > ul > li:nth-child(3)').click(function(){
    $('#display > div.all').hide();
    $('#display > div.offline').show();
  });
});

              
            
!
999px

Console