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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                

	ajax({
				url: 'http://music.qq.com/musicbox/shop/v3/data/hit/hit_all.js',
				jsonp: 'jsonpCallback',
				data: {'callback': 'jsonpCallback'},
				success:function(res){
					JsonCallback(json);
				}
			});
		function JsonCallback(json){

			var data = json.songlist;
			for (var i=0;i<data.length;i++) {
				var width = 300;
				var image_id = data[i].albumId;
				var img = document.createElement("img");
				var pic = "http://imgcache.qq.com/music/photo/album_"+width+"/"+image_id%100+"/"+width+"_albumpic_"+image_id+"_0.jpg";
				img.src = pic;
				document.body.appendChild(img);
			}
		}
function ajax(params) {
	params = params || {};
	params.data = params.data || {};
	var json = params.jsonp ? jsonp(params) : json(params);
	// ajax请求
	function json(params) {
		params.type = (params.type || 'GET').toUpperCase();
		params.data = formatParams(params.data);
		var xhr = null;

		// 实例化XMLHttpRequest对象
		if(window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else {
			// IE6及其以下版本
			xhr = new ActiveXObjcet('Microsoft.XMLHTTP');
		};

		// 监听事件
		xhr.onreadystatechange = function() {
			if(xhr.readyState == 4) {
				var status = xhr.status;
				if(status >= 200 && status < 300) {
					var response = '';
					var type = xhr.getResponseHeader('Content-type');
					if(type.indexOf('xml') !== -1 && xhr.responseXML) {
						response = xhr.responseXML; //Document对象响应
					} else if(type === 'application/json') {
						response = JSON.parse(xhr.responseText); //JSON响应
					} else {
						response = xhr.responseText; //字符串响应
					};
					params.success && params.success(response);
				} else {
					params.error && params.error(status);
				}
			}
		};

		// 连接和传输数据
		if(params.type == 'GET') {
			xhr.open(params.type, params.url + '?' + params.data, true);
			xhr.send(null);
		} else {
			xhr.open(params.type, params.url, true);
			//设置提交时的内容类型
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			xhr.send(params.data);
		}
	}

	// jsonp请求
	function jsonp(params) {
		//创建script标签并加入到页面中
		var callbackName = params.jsonp;
		var head = document.getElementsByTagName('head')[0];
		// 设置传递给后台的回调参数名
		params.data['callback'] = callbackName;
		var data = formatParams(params.data);
		var script = document.createElement('script');
		head.appendChild(script);

		//创建jsonp回调函数
		window[callbackName] = function(json) {
			head.removeChild(script);
			clearTimeout(script.timer);
			window[callbackName] = null;
			params.success && params.success(json);
		};

		//发送请求
		script.src = params.url + '?' + data;

		//超时处理
		if(params.time) {
			script.timer = setTimeout(function() {
				window[callbackName] = null;
				head.removeChild(script);
				params.error && params.error({
					message: '超时'
				});
			}, time);
		}
	};
	//格式化参数
	function formatParams(data) {
		var arr = [];
		for(var name in data) {
			arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name]));
		};
		// 添加一个随机数,防止缓存
		arr.push('v=' + random());
		return arr.join('&');
	}
	// 获取随机数
	function random() {
		return Math.floor(Math.random() * 10000 + 500);
	}
}
              
            
!
999px

Console