立体效果 通过box-shadow 的inset特性,通过适当偏移x,y轴,实现内阴影的立体效果
box-shadow: -5px -5px 30px 1px #0075af inset;
文字转语音实现
基于浏览器提供的SpeechSynthesisUtterance
Api进行实现
SpeechSynthesisUtterance基本属性
SpeechSynthesisUtterance.lang
获取并设置话语的语言SpeechSynthesisUtterance.pitch
获取并设置话语的音调(值越大越尖锐,越低越低沉)SpeechSynthesisUtterance.rate
获取并设置说话的速度(值越大语速越快,越小语速越慢)SpeechSynthesisUtterance.text
获取并设置说话时的文本SpeechSynthesisUtterance.voice
获取并设置说话的声音SpeechSynthesisUtterance.volume
获取并设置说话的音量
SpeechSynthesisUtterance.text基本方法
speak()
将对应的实例添加到语音队列中cancel()
删除队列中所有的语音.如果正在播放,则直接停止pause()
暂停语音resume()
恢复暂停的语音
为按钮添加点击事件,获取input输入框的值,并进行播放,添加眼睛动画,并在播放结束的回调移除眼睛动画
$('#btn').click(function () {
let text = $('#input').val()
if (text) {
$('.eye').addClass('shine')
}
let u = new window.SpeechSynthesisUtterance()
u.text = text
u.lang = 'zh'
u.rate = 0.7
u.onend = function () {
$('.eye').removeClass('shine')
}
speechSynthesis.speak(u)
})
动画类:
.shine {
animation: shine 1s linear infinite;
}
@keyframes shine {
0%{
height: 100px;
}
100%{
height: 0px;
}
}
完整代码:
HTML+CSS