javaScript

chrome控制台新玩法 - console显示

2016-08-19  本文已影响164人  丁小时候

目录

1.输出颜色块

2.输出3D Text

3.输出Colorful CSS

4.输出Rainbow Text

5.在Chrome控制台输出图片

6.输出警告信息3

7.输出错误信息3

8.文字应用样式3

chrome控制台新玩法- console显示

转自:

原文地址

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这样的动态图片也是没问题的

还是应用差不多的代码,只是将内容变成指定背景为图片.

填写图片摘要(选填)

console.log("%c", "padding:50px 300px;line-height:120px;background:url('http://wayouliu.duapp.com/img/tagsImg/youth.gif') no-repeat;");

6.输出警告信息

在正常模式下,和般中能向console控制台输出简单的文字信息.但为了把信息输出得更优雅更便于阅读,除了console.log()方法还可以调用console.warn()来输出警告信息,在控制台中出来的效果如下.

填写图片摘要(选填)

console.warn("whoa! warning goes here...");

在输出信息前面会有一个带感叹号的黄色三角警告符号,似乎比一身孕的consoel信息要友好很多.虽然图标是黄色的,但输出 的文字仍然是黑色

7.输出错误信息

填写图片摘要(选填)

信息前面会出现一个带叉的红色圆形图标.

这个效果比警告信息更友了,字体颜色变成了红色了.

console.error("what error");

8.文字应用样式

要更牛叉的莫过于对文字应用样式,而现在这一特性已经在谷歌浏览器里实现了

在Chrome的开发者工具里,console可以加样式,可以显示缤纷的颜色,甚至图片,.

具体来说,是可以对输出到console控制台的文字进行CSS控制

格式如下:

console.log (“%c需要输出的信息

”,“css代码

”);

谷歌开发者中心上面关于谷歌浏览器控制台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.

上一篇下一篇

猜你喜欢

热点阅读