jquery实现打字效果
2015-12-19 14:48
661 查看
<!doctype html><html dl><head> <title>TypeType</title> <style> body { text-align:center; font-family: Monaco,Menlo,Consolas,"Courier New",monospace; background:rgb(51,51,51); margin:0; } #header { position:absolute; width:100%; top:50%;margin-top:-210px; -webkit-transition:all 1s; transition:all 1s; opacity:0; } .reveal #header { margin-top:-270px; opacity:0.3; } .reveal #header:hover { opacity:0.9; -webkit-transition:all 200ms; transition:all 200ms; } #header, #header a { height:40px; color:white; font-size:30px; text-decoration:none; font-family:'Helvetica Neue',Helvetica,sans-serif; } #header a:hover { text-decoration:underline; } #header iframe { position:absolute; top:0.3em; margin-lefT:0.5em; } .ta { position:absolute; right:50%; top:50%; margin-top:-210px; height:420px; width:420px; background:rgb(35,36,38); z-index:2; -webkit-transition:all 1s, color 400ms, outline 50ms; transition:all 1s, color 400ms, outline 50ms; overflow:hidden; } .textarea { display:block; background:none; height:400px; width:400px; padding:10px; color:rgb(236,236,236); font-size:130%; /* border:1px solid rgb(171,202,243);*/ border:0; } .textarea.dim { color:rgba(236,236,236,0.3); } #rhs { display:block; position:absolute; left:50%; top:50%; margin-top:-210px; height:420px; width:420px; background:rgba(230,230,230,1); white-space:pre; -webkit-transition:all 1s; -transition:all 1s; font-size:80%; overflow:hidden; text-overflow: ellipsis; text-align:left; } #rhs #code { height:400px; width:400px; padding:10px; background:none !important; } .ta { margin-right:-210px; } #rhs { margin-left:-210px; } .reveal .ta, .reveal #rhs { margin-right:0px; margin-left:0px; } #secondhalf { display:none; } #usage { position:absolute; display:block; border:0; background:rgb(209,141,249); background:#bdb; color:#030; z-index:3; display:block; bottom:-70px; left:15px; width:380px; height:3em; padding:5px; overflow:scroll; white-space:pre; opacity:0; -webkit-transition:bottom 1s, opacity 200ms; transition:bottom 1s, opacity 200ms; font-family: Monaco,Menlo,Consolas,"Courier New",monospace; } #usage.show { opacity:0.4; bottom:15px; } #usage:hover { opacity:1; } </style> </head> <body> <div id="header"> typetype by @iamdanfox </div> <div class="ta"> <textarea spellcheck="false" class="textarea"></textarea> <textarea id="usage" title="Just 578 bytes gzipped!" readonly spellcheck='off' wrap='off'><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js" type="text/javascript"></script> <script src="http://iamdanfox.github.io/typetype/jquery.typetype.min.js" type="text/javascript"></script></textarea> </div> <div id="rhs"> <div id="code">$('textarea').focus() .typetype("Sometimes, it's really nice to simulate a human typing...", { callback: function() { $('body').addClass('reveal') } }).delay(1500) .typetype("\n\nThat's what this `typetype` jQuery plugin is for.") <span id="secondhalf"> .fadeTo(400,0.3).delay(1000).queue(function(){$('#secondhalf').fadeIn(1000);$('textarea').dequeue()}).delay(4000).fadeTo(400,1.0).delay(1000) .typetype("\n\nYou can make it fast... ",{ keypress:flashTextarea, t:60, e:0 }) .typetype("or slow and error-prone.", { t:200, e:0.2, // the default error rate is 0.04 }) .backspace(48) .typetype("Try it out!")</span> </div> </div> <script src="http://yandex.st/highlightjs/8.0/highlight.min.js"></script> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript" src="../public/js/jquery/lib/jquery.typetype.min.js"></script> <script type="text/javascript"> function flashTextarea(){ console.log('fl') $('.ta').css({'outline':'1px solid rgba(255,255,0,0.7)'}) setTimeout(function(){ $('.ta').css({'outline':'1px solid rgba(255,255,0,0)'}) },50) } $(function(){ hljs.configure({languages:['js']}) hljs.highlightBlock($('#code')[0]) $('#usage').click(function(){ this.focus() this.select() }) $('.textarea').focus() .typetype("Sometimes, it's really nice to simulate a human typing...", { callback: function() { $('body').addClass('reveal') } }).delay(1500) .typetype("\n\nThat's what this `typetype` jQuery plugin is for.") .fadeTo(400,0.3).delay(1000).queue(function(){$('#secondhalf').fadeIn(1000);$('textarea').dequeue()}).delay(4000).fadeTo(400,1.0).delay(1000) .typetype("\n\nYou can make it fast... ",{ keypress:flashTextarea, t:60, e:0 }) .typetype("or slow and error-prone.", { t:200, e:0.2, // the default error rate is 0.04 callback: function(){ $("#usage").addClass('show') } }) .backspace(48) .typetype("Try it out!") }) </script> </body> </html>
<!doctype html> <html> <head> <title>TypeType</title> <script src="../public/js/jquery/jquery-1.8.2.min.js"></script> <script src="../public/js/jquery/lib/jquery.typetype.min.js"></script> <script> $(function(){ $('textarea') .typetype('Hello, world!') .delay(1000) .typetype('\n\nGoodbye.') .backspace(25) .fadeOut() // jQuery效果 }); </script> <style> </style> </head> <body> <textarea></textarea> </body> </html>
相关文章推荐
- Web前端国际化之jQuery.i18n.properties
- jQuery面向对象的写法
- JQuery的源码阅读
- jquery mobile在页面中间有一个灰色的圆圈
- Jquery库和自己编写的base.js之间的冲突
- Css和Jquery的一些学习认识(一)
- jquery2.0动态绑定事件
- jQuery异步请求(如getJSON)跨域解决方案
- jQuery源码分析之jQuery(selector,context)详解
- 15个常用的jquery代码片段
- 在jQuery代码中,实现转跳
- 15个常用的jquery代码片段
- 基于jquery实现页面滚动到底自动加载数据的功能
- jquery-mobile(二)
- jquery-mobile(一)
- jQuery问题集锦
- jquery mobile 移动web(2)
- 【jQuery】使用ajaxStart()和ajaxStop()方法
- 【jQuery】使用ajaxSetup()方法设置全局Ajax默认选项
- 【jQuery】使用ajax()方法加载服务器数据