霓虹灯条 css_使用CSS创建闪烁的霓虹灯条

霓虹灯条 css

Demonstrating a neon tubing typographic effect to my 1st year students last week, I realized that I had neglected to animate it as promised… so here it is.

演示霓虹灯管的排版效果上周我的第1年的学生,我意识到,我忽略了它的动画如许......所以在这儿呢。

The base code of this example is very similar to the previous article: an embedded font, use of text-shadow, and a background-image:

此示例的基本代码与上一篇文章非常相似: 嵌入式字体text-shadow使用和background-image

h1#neon-tubing {
	padding: 6rem;
	text-align: center;
	color: rgba(255,200,200,0.8);
	font-family: Neon80s, sans-serif;
	font-size: 11rem;
	letter-spacing: 2rem;
	background: url(brick-wall-texture-faded.jpg);
	background-size: cover;
}

There are two primary differences: a single letter of the neon sign is contained within a span element:

有两个主要区别: span元素内包含一个霓虹灯字母:

<h1 id="neon-tubing">B<span>A</span>R</h1>

… and there is a CSS keyframe animation sequence (shown sans vendor prefixes to save on space):

...并有一个CSS关键帧动画序列 (SANS显示供应商的前缀 ,以节省空间):

@keyframes neonspark  {
	0% {
		text-shadow: none;
	}
	30% {
		text-shadow: 0 0 30px rgba(255,0,84,0.6);
	}
	60% {
		text-shadow: 0 0 30px rgba(255,0,84,0.6),
		  0 0 60px rgba(255,0,84,0.4);
	}
	80% {
		text-shadow: none;
	}
	100% {
		text-shadow: 0 0 30px rgba(255,0,84,0.6),
		 0 0 60px rgba(255,0,84,0.4), 
		 0 0 100px rgba(255,0,84,0.2), 
		 0 0 90px rgba(255,0,84,0.1);
	}
}

The sequence is simple, merely adding and removing a text-shadow to the letters. The trick is that both the <h1> element and the <span> use the keyframes in different ways:

序列很简单,只需在字母上添加和删除text-shadow 。 诀窍是<h1>元素和<span>以不同的方式使用关键帧:

h1#neon-tubing {
	animation: neonspark 1s 3s forwards;
	}
	h1#neon-tubing span {
		animation: neonspark 4s 3s infinite;
	}

The final effect is that the sign as a whole flickers into life once (as the default behaviour is for CSS animations to execute a single time) but the <span> element uses the same sequence repeatedly, flickering the "A" in the bar sign on and off forever.

最终效果是,整个符号闪烁一次(因为默认行为是CSS动画一次执行),但是<span>元素重复使用相同的序列,从而使条形符号中的“ A”闪烁永远开启和关闭。

This example goes some way towards showing the flexibility and reusability of CSS keyframes: much like object-oriented classes, well-planned keyframes can be applied to multiple elements in different ways on your web pages.

该示例以某种方式展示了CSS关键帧的灵活性和可重用性: 与面向对象的类非常相似,精心设计的关键帧可以以不同的方式应用于网页上的多个元素。

翻译自: https://thenewcode.com/610/Create-A-Flickering-Neon-Bar-Sign-With-CSS

霓虹灯条 css

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值