目錄
1.輸出顏色塊
2.輸出3D Text
3.輸出Colorful CSS
4.輸出Rainbow Text
5.在Chrome控制臺輸出圖片
6.輸出警告信息3
7.輸出錯誤信息3
8.文字應(yīng)用樣式3
chrome控制臺新玩法- console顯示
轉(zhuǎn)自:
http://www.cnblogs.com/Wayou/p/chrome_dev_tool_style_console.html
1.輸出顏色塊
console.log("%c", "padding:50px 300px;line-height:120px;background:red;");
2.輸出3D Text
console.log("%c3D Text"," text-shadow: 0 1px 0 #ccc,0 2px 0 #c9c9c9,0 3px 0 #bbb,0 4px 0 #b9b9b9,0 5px 0 #aaa,0 6px 1px rgba(0,0,0,.1),0 0 5px rgba(0,0,0,.1),0 1px 3px rgba(0,0,0,.3),0 3px 5px rgba(0,0,0,.2),0 5px 10px rgba(0,0,0,.25),0 10px 10px rgba(0,0,0,.2),0 20px 20px rgba(0,0,0,.15);font-size:5em")
3.輸出Colorful CSS
console.log("%cColorful CSS","background: rgba(252,234,187,1);background: -moz-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%,rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: -webkit-gradient(left top, right top, color-stop(0%, rgba(252,234,187,1)), color-stop(12%, rgba(175,250,77,1)), color-stop(28%, rgba(0,247,49,1)), color-stop(39%, rgba(0,210,247,1)), color-stop(51%, rgba(0,189,247,1)), color-stop(64%, rgba(133,108,217,1)), color-stop(78%, rgba(177,0,247,1)), color-stop(87%, rgba(247,0,189,1)), color-stop(100%, rgba(245,22,52,1)));background: -webkit-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: -o-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: -ms-linear-gradient(left, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);background: linear-gradient(to right, rgba(252,234,187,1) 0%, rgba(175,250,77,1) 12%, rgba(0,247,49,1) 28%, rgba(0,210,247,1) 39%, rgba(0,189,247,1) 51%, rgba(133,108,217,1) 64%, rgba(177,0,247,1) 78%, rgba(247,0,189,1) 87%, rgba(245,22,52,1) 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fceabb', endColorstr='#f51634', GradientType=1 );font-size:5em")
4.輸出Rainbow Text
console.log('%cRainbow Text ', 'background-image:-webkit-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );color:transparent;-webkit-background-clip: text;font-size:5em;');
5.在Chrome控制臺輸出圖片
除了上面介紹的那些炫目的文字效果外,你還可以在Chrome控制臺中顯示圖片,顯示gif這樣的動態(tài)圖片也是沒問題的
還是應(yīng)用差不多的代碼,只是將內(nèi)容變成指定背景為圖片.
console.log("%c", "padding:50px 300px;line-height:120px;background:url('http://wayouliu.duapp.com/img/tagsImg/youth.gif') no-repeat;");
6.輸出警告信息
在正常模式下,和般中能向console控制臺輸出簡單的文字信息.但為了把信息輸出得更優(yōu)雅更便于閱讀,除了console.log()方法還可以調(diào)用console.warn()來輸出警告信息,在控制臺中出來的效果如下.
console.warn("whoa! warning goes here...");
在輸出信息前面會有一個帶感嘆號的黃色三角警告符號,似乎比一身孕的consoel信息要友好很多.雖然圖標(biāo)是黃色的,但輸出 的文字仍然是黑色
7.輸出錯誤信息
信息前面會出現(xiàn)一個帶叉的紅色圓形圖標(biāo).
這個效果比警告信息更友了,字體顏色變成了紅色了.
console.error("what error");
8.文字應(yīng)用樣式
要更牛叉的莫過于對文字應(yīng)用樣式,而現(xiàn)在這一特性已經(jīng)在谷歌瀏覽器里實(shí)現(xiàn)了
在Chrome的開發(fā)者工具里,console可以加樣式,可以顯示繽紛的顏色,甚至圖片,.
具體來說,是可以對輸出到console控制臺的文字進(jìn)行CSS控制
格式如下:
console.log (“%c需要輸出的信息
”,“css代碼
”);
谷歌開發(fā)者中心上面關(guān)于谷歌瀏覽器控制臺console.log()的文檔
:
Format Specifier
Description
%s
Formats the value as a string.
%dor%i
Formats the value as an integer.
%f
Formats the value as a floating point value.
%o
Formats the value as an expandable DOM element (as in the Elements panel).
%O
Formats the value as an expandable JavaScript object.
%c
Formats the output string according to CSS styles you provide.