英语信件

How to create an animated old letter Today we will create an animated old letter. In this letter, we will use an animated pen. When the pen dries out – we’ll dip it in the ink. And even more, we add the feature to emulate the errors that will be erased during typing. Now let’s look at the implementation.

如何创建动画旧字母今天,我们将创建动画旧字母。 在这封信中,我们将使用动画笔。 当笔变干时–我们将其浸入墨水中。 甚至更多,我们添加了该功能来模拟将在键入过程中消除的错误。 现在让我们看一下实现。

现场演示

步骤1. HTML (Step 1. HTML)

As the first step, we should prepare basic html file with our letter:

第一步,我们应该准备带字母的基本html文件:

index.html (index.html)

<div id="letter"></div><img id="inkwell1" src="inkwell1.gif" alt="inkwell1" /><img id="inkwell2" src="inkwell2.gif" alt="inkwell2" /><div id="letter_src">
A man named Grant once foi|und a box of old Papers in his dwelling||||||||house. Grant didn't like old things. So he burned most of the papers. But one of these papers was a letter. He read it. A well-known writer had written it.<br><br>
'About a million|||||||hundred years ago nobody know about him|||this writer,' thought Grant. 'Nobody read his books. But now everybody reads him. Some people like to buy old letters. I can get a lot of money for this letter.'<br><br>
But the letter looked dirty. So Grant decided to wash |||||clean it. He worked hard and soon the letter looked new. Grant was not|||||||was very happy.<br><br>
He took the letter to a shop in London where they bought and sold old papers. 'I want to sell this letter,' Grant said to the man in shop. 'It is a well-known writer's letter. How much will you give me for it?'<br><br>
The man looked at the letter for a long time. 'I'll give you two pounds for it,' he said at last.<br><br>
'Only two pounds!' said Grant. 'But people pay ten pounds for old letters. And I have even cleaned it.'<br><br>
'I can see that,' said the man. 'That's the mistake. People who buy old papers like dirty papers more than clean papers.'<br><br></div>
<div id="letter"></div><img id="inkwell1" src="inkwell1.gif" alt="inkwell1" /><img id="inkwell2" src="inkwell2.gif" alt="inkwell2" /><div id="letter_src">
A man named Grant once foi|und a box of old Papers in his dwelling||||||||house. Grant didn't like old things. So he burned most of the papers. But one of these papers was a letter. He read it. A well-known writer had written it.<br><br>
'About a million|||||||hundred years ago nobody know about him|||this writer,' thought Grant. 'Nobody read his books. But now everybody reads him. Some people like to buy old letters. I can get a lot of money for this letter.'<br><br>
But the letter looked dirty. So Grant decided to wash |||||clean it. He worked hard and soon the letter looked new. Grant was not|||||||was very happy.<br><br>
He took the letter to a shop in London where they bought and sold old papers. 'I want to sell this letter,' Grant said to the man in shop. 'It is a well-known writer's letter. How much will you give me for it?'<br><br>
The man looked at the letter for a long time. 'I'll give you two pounds for it,' he said at last.<br><br>
'Only two pounds!' said Grant. 'But people pay ten pounds for old letters. And I have even cleaned it.'<br><br>
'I can see that,' said the man. 'That's the mistake. People who buy old papers like dirty papers more than clean papers.'<br><br></div>

There are a letter source (which will be hidden), an empty container for future letter, and 2 fixed images (to display an ink and dipping pen in the ink.

有一个信源(将被隐藏),一个空容器以备以后的信和两个固定图像(以显示墨水和墨水中的蘸水笔)。

步骤2. CSS (Step 2. CSS)

Before we start preparing the main JavaScript code, let’s customize our design:

在开始准备主要JavaScript代码之前,让我们自定义设计:

style.css (style.css)


body {background: url('bg.jpg') no-repeat center center fixed;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover;
}
#inkwell1 {bottom: 100px;left: 140px;position: fixed;
}
#inkwell2 {bottom: 100px;left: 140px;position: fixed;visibility: hidden;
}
#letter {font-family: Comic Sans MS;font-size: 18px;font-weight: bold;margin: 50px auto;position: relative;width: 75%;
}
#letter_src {display: none;
}

body {background: url('bg.jpg') no-repeat center center fixed;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover;
}
#inkwell1 {bottom: 100px;left: 140px;position: fixed;
}
#inkwell2 {bottom: 100px;left: 140px;position: fixed;visibility: hidden;
}
#letter {font-family: Comic Sans MS;font-size: 18px;font-weight: bold;margin: 50px auto;position: relative;width: 75%;
}
#letter_src {display: none;
}

As you can see – both ink images are fixed, and letter source is hidden by default.

如您所见–墨迹图像都是固定的,默认情况下字母来源是隐藏的。

步骤3. JavaScript (Step 3. JavaScript)

Now we are ready to the main javascript code:

现在我们准备好主要JavaScript代码:

script.js (script.js)


window.onload = function(){// public variablesvar vLetter = document.getElementById('letter');var iSpeedInk = 5;// other variablesvar sText = document.getElementById('letter_src').innerHTML;var iCurChar = 0;var sChars = '<span>';var iCurInk = 0;var sCurCaret = '';var sCaret = "&nbsp;<img src='pen.gif' style='position:absolute' />";var doStep = function () {// current charvar sChar = sText.charAt(iCurChar);// default char delayvar iDelay = 32;if (sChar == '') {sCurCaret = '';} else if (sChar == '|') { // we use | symbol to emulate 'error' symbolsChar = '';sChars = sChars.substring(0, sChars.length-1);iDelay = 64;} else if (sChar == '<') { // pass tagsvar iPos = sText.indexOf('>', iCurChar);sChar = sText.substring(iCurChar, iPos + 1);iCurChar = iPos;} else if (sChar == '&') { // pass html entitiesvar iPos = sText.indexOf(';', iCurChar);sChar = sText.substring(iCurChar, iPos + 1);iCurChar = iPos;} else if (sChar == '.') { // custom delay in case of . symboliDelay = 300;} else if (sChar == ',') { // custom delay in case of , symboliDelay = 100;} else if (sChar == ' ') { // custom delay in case of space symboliDelay = 32;} else if (iCurChar > 5) {sCurCaret = sCaret;}// expenditure of inkif (sChar == ' ') {iCurInk += iSpeedInk;sChar = '</span><span style="color:RGB(' + (iCurInk) + ',' + (iCurInk) + ',' + (iCurInk) + ')">' + sChar;}if (document.getElementById('inkwell2').style.visibility == 'visible') {sCurCaret = sCaret;document.getElementById('inkwell2').style.visibility = 'hidden';sChar = '</span><span style="color:RGB(0,0,0)">' + sChar;}// refresh Inkif (iCurInk > 160) {iCurInk = 0;document.getElementById('inkwell2').style.visibility = 'visible';iDelay = 1000;sCurCaret = '';}// add current char to charssChars += sChar;// hide the caret at the end of the letterif (iCurChar == sText.length - 1)sCurCaret = '';// update letter with new charsvLetter.innerHTML = sChars + sCurCaret;// goto next chariCurChar++;// next stepif (iCurChar < sText.length) {setTimeout(doStep, 20 + iDelay);}}doStep();
};

window.onload = function(){// public variablesvar vLetter = document.getElementById('letter');var iSpeedInk = 5;// other variablesvar sText = document.getElementById('letter_src').innerHTML;var iCurChar = 0;var sChars = '<span>';var iCurInk = 0;var sCurCaret = '';var sCaret = "&nbsp;<img src='pen.gif' style='position:absolute' />";var doStep = function () {// current charvar sChar = sText.charAt(iCurChar);// default char delayvar iDelay = 32;if (sChar == '') {sCurCaret = '';} else if (sChar == '|') { // we use | symbol to emulate 'error' symbolsChar = '';sChars = sChars.substring(0, sChars.length-1);iDelay = 64;} else if (sChar == '<') { // pass tagsvar iPos = sText.indexOf('>', iCurChar);sChar = sText.substring(iCurChar, iPos + 1);iCurChar = iPos;} else if (sChar == '&') { // pass html entitiesvar iPos = sText.indexOf(';', iCurChar);sChar = sText.substring(iCurChar, iPos + 1);iCurChar = iPos;} else if (sChar == '.') { // custom delay in case of . symboliDelay = 300;} else if (sChar == ',') { // custom delay in case of , symboliDelay = 100;} else if (sChar == ' ') { // custom delay in case of space symboliDelay = 32;} else if (iCurChar > 5) {sCurCaret = sCaret;}// expenditure of inkif (sChar == ' ') {iCurInk += iSpeedInk;sChar = '</span><span style="color:RGB(' + (iCurInk) + ',' + (iCurInk) + ',' + (iCurInk) + ')">' + sChar;}if (document.getElementById('inkwell2').style.visibility == 'visible') {sCurCaret = sCaret;document.getElementById('inkwell2').style.visibility = 'hidden';sChar = '</span><span style="color:RGB(0,0,0)">' + sChar;}// refresh Inkif (iCurInk > 160) {iCurInk = 0;document.getElementById('inkwell2').style.visibility = 'visible';iDelay = 1000;sCurCaret = '';}// add current char to charssChars += sChar;// hide the caret at the end of the letterif (iCurChar == sText.length - 1)sCurCaret = '';// update letter with new charsvLetter.innerHTML = sChars + sCurCaret;// goto next chariCurChar++;// next stepif (iCurChar < sText.length) {setTimeout(doStep, 20 + iDelay);}}doStep();
};

The main idea – to produce all the symbols of the letter one by one. Depending on a current character we can set different delays and simulate errors. In order to simulate ‘the expenditure of ink’ – we check for space symbol, in the result – each word has own color (gray gradation). When this color is pretty white – we ‘dip’ it into our ‘inkwell’.

主要思想–逐一生成字母的所有符号。 根据当前角色,我们可以设置不同的延迟并模拟错误。 为了模拟“墨水消耗”,我们检查结果中的空格,每个单词都有自己的颜色(灰色渐变)。 如果该颜色是白色,则将其“浸入”到“墨池”中。

现场演示

[sociallocker]

[社交储物柜]

下载包

[/sociallocker]

[/ sociallocker]

结论 (Conclusion)

I hope that everything is clean in today’s tutorial. If you have any suggestions about further ideas for articles – you are welcome to share them with us. Good luck in your work!

我希望今天的教程一切正常。 如果您对文章的进一步建议有任何建议,欢迎与我们分享。 祝您工作顺利!

翻译自: https://www.script-tutorials.com/animated-old-letter/

英语信件

英语信件_如何创建动画的旧信件相关推荐

  1. python动画精灵_如何使用Adafruit的CircuitPython创建动画精灵

    概述 马里奥云与烤面包机 在此项目中,我们正在制作复古风格的可穿戴设备! 吊坠具有IPS显示屏和动画图形.它使用Adafruit的CircuitPython创建动画精灵,看起来像是在飞行的烤面包机和滚 ...

  2. animator创建动画_为游戏创建动画的基础

    animator创建动画 You can consider animation as the technique or procedure of making the illusion of moti ...

  3. fireworks 投影_使用Fireworks文章创建动画

    fireworks 投影 Multimedia-rich sites were once shunned on the Web. "No!" cried the nay-sayer ...

  4. 怎么创建mysql文件_怎样创建数据库?

    谢邀~树懒君精心整理了一番,接下来就4种流行数据库的创建方法介绍. 一.创建数据库简介 数据库是储存关键资料的文件系统,用数据库管理系统建立大家的数据库,就可以更好地提供安全性.如今伴随着社会发展的迅 ...

  5. 使用Python,OpenCV创建动画GIF图和模因生成器

    在这篇博客中,我们将学习如何使用Python,OpenCV,dlib和ImageMagick工具箱创建动画GIF. 然后,您将结合所有这些技术,使用OpenCV构建一个模因生成器(眼镜

  6. 【Flutter】Animation 动画 ( AnimatedBuilder 动画使用流程 | 创建动画控制器 | 创建动画 | 创建动画作用的组件 | 关联动画与组件 | 动画执行 )

    文章目录 ◯.AnimatedBuilder 引入 一.创建动画控制器 二.创建动画 三.创建动画作用的组件 四.创建 AnimatedBuilder 关联动画与组件 五.动画运行 六.完整代码示例 ...

  7. 【Flutter】Animation 动画 ( AnimatedWidget 动画使用流程 | 创建动画控制器 | 创建动画 | 创建 AnimatedWidget 动画组件 | 动画运行 )

    文章目录 ◯.AnimatedWidget 组件引入 一.创建 AnimatedWidget 动画组件 二.创建动画控制器 三.创建动画 四.动画运行 五.完整代码示例 六.相关资源 Animated ...

  8. 【Flutter】Animation 动画 ( Flutter 动画基本流程 | 创建动画控制器 | 创建动画 | 设置值监听器 | 设置状态监听器 | 布局中使用动画值 | 动画运行 )

    文章目录 一.创建动画控制器 二.创建动画 三.设置值监听器 四.设置状态监听器 五.布局中使用动画值 六.动画运行 七.完整代码示例 八.相关资源 Flutter 动画基本流程 : ① 创建动画控制 ...

  9. Android复习15【动画:创建资源文件夹、创建动画资源文件、组合动画、属性动画、材料设计新特性】

    2020-05-09-[12周-周四] Android动画 https://blog.csdn.net/zhangbijun1230/article/details/80262359 https:// ...

最新文章

  1. 产品经理经常使用工具
  2. 中国互联网+政务建设发展现状及市场规模预测报告2022-2027年版
  3. 三相同步电机怎么接线图_智能电表怎么接线 单相 三相电表接线图大全
  4. OC基础1:一些基本概念
  5. Python——format()/str.format()函数
  6. winform 属性
  7. 《HTTP权威指南》学习总结1——HTTP协议概述
  8. Maven 使用入门
  9. 胧月初音未来计算机,胧月(流星P所作歌曲《胧月》)_百度百科
  10. 快速刷微信小程序访问量和浏览量
  11. 申报深圳市专精特新中小企业需要哪些条件,及有什么好处
  12. 免费可商用图片网站合集
  13. html5考试总结300字,期中考试总结作文300字合集五篇
  14. 钓鱼c语言,C语言实现小猫钓鱼游戏
  15. ffi一些常见的错误
  16. 仿微信视频下载进度自定义View
  17. STM32串口屏学习
  18. solr的copyFeild用法(改变各个feild的权重,修改打分结果)-注意!
  19. redis常用命令总结,一文足以(5种基本数据结构+bitmap+Geo+HyperLogLog+Streams)
  20. 苹果手机html吊起拍照,用苹果手机拍照,打开这2个“万能模式”,轻松拍出好照片...

热门文章

  1. LBP+SVM 活体识别
  2. Unity3D 工程机械以及常见机构铰链,关节绑定 插件
  3. Winform实现类似Viso的简单的流程图
  4. 利用Cobalt Strike通过exe木马实现远控|Cobalt Strike远程控制|Cobalt Strike 使用方法|CS使用方法
  5. Quorum联盟链开发入门
  6. 用酒精Alcohol 120%刻WI-IC的OS简单教程
  7. 壁纸 | 隐藏iPhone Dock栏
  8. 端口问题让HP1010在WIN7下打印速度超慢
  9. C++程序设计分析 (基于谭书第三版)
  10. unity3D实现地对空防御