当前位置: 首页 > news >正文

html5随机选取文本框,HTML5交互式电子邮件(带输入框和选择框)

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

const divider = '------------------------------';

let turk = {

queue: [],

styleTarget: '#css',

presentationTarget: '#code pre code',

htmlTarget: '#email',

els: {},

wait(delay) {

this.queue.push({

delay

});

},

space(lines = 1) {

this.queue.push({

type: 'space',

contents: Array(lines + 1).join('\n')

});

},

progressBar(delay) {

const spaces = 20;

const otherChars = '/* */'.length;

this.addComment({

contents: Array(spaces).join('='),

speed: delay / (spaces + otherChars)

});

},

addHTML({

action = 'append', contents = '
', target = this.htmlTarget, delay = 750

}) {

this.queue.push({

type: 'html',

action,

contents,

target,

delay

});

},

addCSS({

contents = '', delay, speed

}) {

this.queue.push({

type: 'css',

contents,

delay,

speed

});

},

addComment({

contents = '', delay, speed

}) {

this.queue.push({

type: 'comment',

contents,

delay,

speed

});

},

run() {

this.els = {

style: $(this.styleTarget),

presentation: $(this.presentationTarget),

css: $(`${this.styleTarget}, ${this.presentationTarget}`),

html: $(this.htmlTarget)

};

this.next();

},

next() {

if (this.queue.length === 0) {

return console.log('done');

}

let typingPromise = Promise.resolve();

const item = this.queue.shift();

switch (item.type) {

case 'space':

typingPromise = write(this.els.css, item.contents);

break;

case 'comment':

let comment = item.contents.split('\n').length > 1 ?

`/* ${item.contents.replace(/\n/gm, '\n * ')}\n */\n\n` :

`/* ${item.contents} */\n`;

typingPromise = write(this.els.css, comment, item.speed);

break;

case 'css':

typingPromise = write(this.els.css, `${this.htmlTarget} ${item.contents}\n\n`, item.speed);

break;

case 'html':

if (item.action === 'append') {

$(item.contents).appendTo(item.target);

}

if (item.action === 'wrap') {

$(item.target).wrapAll(item.contents);

}

if (item.action === 'prepend') {

$(item.target).prepend(item.contents);

}

break;

}

typingPromise

.then(() => wait(item.delay || 300))

.then(() => {

this.next();

});

}

};

function wait(time = 0) {

return new Promise((resolve, reject) => {

setTimeout(() => {

resolve()

}, time);

});

}

function scrollToBottom() {

// turk.els.presentation.animate({ scrollTop: turk.els.presentation[0].scrollHeight });

}

function write($target, str, speed = 40) {

if (str.length === 0) {

return Promise.resolve();

}

return new Promise((resolve, reject) => {

$target.append(str.charAt(0));

scrollToBottom($target);

setTimeout(() => {

write($target, str.substr(1), speed).then(resolve);

}, speed);

})

}

// building the queue

turk.addComment({

contents: `Hey there!

Lets learn about interactive email.

Interactive email

> An interactive email has the functionality for users

> to take an action within the email that triggers an

> event within the same email.`

});

turk.addComment({

contents: `How does that work?

Email clients like gmail strip out JavaScript to protect

us from dangerous senders. But there are some pretty cool

CSS hacks out there to still make emails interactive.

We use some checkbox magic!

We need a client that supports 3 things

1. the \`\` tag

2. the \`:checked\` selector

3. the \`+\` and \`~\` selectors to target siblings`

});

turk.space();

turk.wait(300);

turk.addComment({

contents: `Lets get started

${divider}`

});

turk.addComment({

contents: `We'll start with a label....`

});

turk.space();

turk.addHTML({

contents: 'Click me!'

});

turk.addComment({

contents: `a checkbox....`

});

turk.space();

turk.addHTML({

contents: ''

});

turk.addComment({

contents: `and content we want to show after we click the 'button'....`

});

turk.space();

turk.addHTML({

contents: '

You clicked the button!
'

});

turk.addComment({

contents: `Lets make our label look like a button.`

});

turk.addCSS({

contents: `#button {

background: coral;

color: white;

padding: 0.67em 1em;

display: inline-block;

cursor: pointer;

}`

});

turk.addComment({

contents: `Hmm, lets make that easier to see.`

});

turk.addCSS({

contents: `* {

font-size: 16px;

}`

});

turk.space();

turk.addComment({

contents: `Next we'll hide the #magic-content.`

});

turk.addCSS({

contents: `#magic-content {

display: none;

}`

})

turk.addComment({

contents: `Now lets show the \`#magic-content\` when the checkbox is checked.`

});

turk.addCSS({

contents: `#button-hook:checked ~ #magic-content {

display: inline-block;

}`

});

turk.space();

turk.addComment({

contents: `Give it a try!`

});

turk.progressBar(8000);

turk.space(3);

turk.addComment({

contents: `Ok, but this doesn't work everywhere.

We need to create a fallback for those poor souls that won't get our

awesome super advanced email.`

});

turk.addComment({

contents: `We'll wrap our interactive content in a div

with the id \`#interactive\`...`

})

turk.addHTML({

contents: `

action: 'wrap',

target: `${turk.htmlTarget} *`

});

turk.space();

turk.addComment({

contents: `add a checked checkbox right before \`#interactive\`...`

});

turk.addHTML({

contents: ``,

action: 'prepend',

target: turk.htmlTarget

});

turk.space();

turk.addComment({

contents: `and we'll hide the interactive content by default.`

});

turk.addCSS({

contents: `#interactive {

display: none;

}`

});

turk.addComment({

contents: `Next, we'll override that when its next to a checked checkbox...which it is!`

});

turk.addCSS({

contents: `#interactive-hook:checked ~ #interactive {

display: block;

}`

});

turk.addComment({

contents: `Now if the client support the css we need it will work but

if it doesn't our interactive content won't show.`

});

turk.addComment({

contents: `Lastly, we need some fallback content.`

});

turk.addHTML({

contents: `Dude, get a better email client.`

});

turk.space();

turk.addComment({

contents: `Lets apply the same idea as before and flip the styles.

We'll show \`#fallback\` by default and hide it if its next to a checked checkbox.`

});

turk.addCSS({

contents: `#interactive-hook:checked ~ #fallback {

display: none;

}`

});

turk.addComment({

contents: `Lets clean it all up...`

});

turk.addCSS({

contents: `#button-hook, #interactive-hook {

display: none !important;

}`

});

turk.addComment({

contents: `Wooo! We successfully made an interactive email with a safe fallback`

});

// turk.addHTML({ contents: `

Sign up for SparkPost to start sending your awesome, interactive emails
` });

turk.run();

相关文章:

  • html格子切换效果图,(HTML)关于格子流布局方案可以如此设计
  • android密码设成星号,将EditText密码掩码字符更改为星号(*)
  • 江西赣州信丰2021高考成绩查询,2021上半年江西信丰县教资面试成绩查询入口
  • 计算机应用bsp什么意思,bsp是什么
  • 指利用计算机技术实现对文本篇章的理解,【人工智能课|人工智能自然语言处理技术是什么】- 环球网校...
  • 微型计算机结构认识,认识《微机原理》
  • 土木工程计算机仿真学科未来前景,土木工程学院土木工程计算机仿真2010级学历教育硕士--培养方案...
  • 本科会计大二转学美国学计算机,国内本科生可以转学去美国:最佳时机在大二!...
  • 分级列表html,CSS分级属性 二
  • html计算机之间的距离,【百思不得其解~求助】html网页编程:求输入的两个数之间的所有质...
  • 计算机游戏7步变28,亲子游戏100种
  • 我的未来规划作文计算机,我的未来规划500字作文
  • 我们一起学猫叫歌曲计算机,我们一起学猫叫一起喵喵喵喵喵是什么歌
  • 池州学院期末计算机考试题,池州学院数据库期末模试卷1.doc
  • 抖音计算机音乐你要我,抖音我要记住你的样子是什么歌
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • Centos6.8 使用rpm安装mysql5.7
  • interface和setter,getter
  • leetcode388. Longest Absolute File Path
  • php ci框架整合银盛支付
  • Phpstorm怎样批量删除空行?
  • Redis学习笔记 - pipline(流水线、管道)
  • Storybook 5.0正式发布:有史以来变化最大的版本\n
  • 数据仓库的几种建模方法
  • 通过几道题目学习二叉搜索树
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 原创:新手布局福音!微信小程序使用flex的一些基础样式属性(一)
  • 关于Android全面屏虚拟导航栏的适配总结
  • 支付宝花15年解决的这个问题,顶得上做出十个支付宝 ...
  • ​queue --- 一个同步的队列类​
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • #!/usr/bin/python与#!/usr/bin/env python的区别
  • #我与Java虚拟机的故事#连载16:打开Java世界大门的钥匙
  • (+3)1.3敏捷宣言与敏捷过程的特点
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (二)学习JVM —— 垃圾回收机制
  • (七)c52学习之旅-中断
  • (十)T检验-第一部分
  • (四)linux文件内容查看
  • (转)程序员技术练级攻略
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .net oracle 连接超时_Mysql连接数据库异常汇总【必收藏】
  • .net redis定时_一场由fork引发的超时,让我们重新探讨了Redis的抖动问题
  • .NET/C# 获取一个正在运行的进程的命令行参数
  • .NET/C# 如何获取当前进程的 CPU 和内存占用?如何获取全局 CPU 和内存占用?
  • .NET/C# 中设置当发生某个特定异常时进入断点(不借助 Visual Studio 的纯代码实现)
  • .netcore 如何获取系统中所有session_ASP.NET Core如何解决分布式Session一致性问题
  • .netcore 如何获取系统中所有session_如何把百度推广中获取的线索(基木鱼,电话,百度商桥等)同步到企业微信或者企业CRM等企业营销系统中...
  • .NET开源快速、强大、免费的电子表格组件
  • .net利用SQLBulkCopy进行数据库之间的大批量数据传递
  • .net连接oracle数据库
  • []C/C++读取串口接收到的数据程序
  • [《百万宝贝》观后]To be or not to be?
  • [28期] lamp兄弟连28期学员手册,请大家务必看一下