|
来历:知乎
视频及在线演示
HTML建造3D樱花漫天飞舞及信封
https://www.zhihu.com/video/1455525300347645953
HTML5建造3D樱花漫天飞舞及浪漫信封
浪漫信封:http://haiyong.site/eluvletter
3D樱花漫天飞舞:http://haiyong.site/yinghua
下方可获得完整源码
浪漫信封
HTML 内容
<div id=&#34;jsi-cherry-container&#34;></div> <section class=&#34;container&#34; id=&#34;contact&#34; > <form class=&#34;flip&#34;> <div class=&#34;front&#34;> <h2>To Ming</h2> <a id=&#34;flip2back&#34; href=&#34;#&#34;>Flip</a> </div> <div id=&#34;content&#34; class=&#34;back&#34;> <div id=&#34;letter&#34;> <div class=&#34;container&#34;> <div class=&#34;flip&#34;> <div class=&#34;front&#34;></div> <div class=&#34;back&#34;> <p class=&#34;letter&#34;></p> <a id=&#34;close&#34; href=&#34;#&#34;>Close</a> </div> </div> </div> </div> <div id=&#34;top&#34;> <a id=&#34;flip&#34; href=&#34;#contact&#34;>Flip</a> </div> <div id=&#34;lid&#34; class=&#34;container&#34;> <div class=&#34;flip&#34;> <div class=&#34;front&#34;> <a id=&#34;open&#34; href=&#34;#content&#34;><span></span></a> </div> <div class=&#34;back&#34;></div> </div> </div> </div> </form> </section> <div id=&#34;footer&#34;> <audio id=&#34;music2&#34; preload=&#34;auto&#34; loop></audio> <a id=&#34;music_btn2&#34; href=&#34;javascript:playPause();&#34;></a> </div>部分CSS
#letter { background: #fafafa; width: 90%; height: 95%; position: absolute; left: 5%; top: 5%; z-index: 0; -webkit-transition: .5s .5s; -moz-transition: .5s .5s; -o-transition: 0s 0s; transition: 0s 0s; } #content:target #letter { top: -40%; -o-transition: .5s .5s; transition: .5s .5s; } #letter .container { position: absolute; width: 100%; /*height: 50%;*/ -webkit-perspective: 800px; -moz-perspective: 800px; perspective: 800px; top: 0; left: 0; -webkit-transition: 0s 0s; -moz-transition: 0s 0s; transition: 0s 0s; z-index: 1; } #letter .flip { width: 100%; height: 100%; } #letter .flip { position: absolute; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-transition: -webkit-transform 0.5s 0s; -moz-transition: -moz-transform 0.5s 0s; transition: -moz-transform 0.5s 0s; -webkit-transform-origin: left top; -moz-transform-origin: left top; transform-origin: left top; } #letter .flip > .front, #letter .flip > .back { position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; backface-visibility: hidden; } #letter .flip > .back { -webkit-transform: rotateX(180deg); -moz-transform: rotateX(180deg); transform: rotateX(180deg); } #content:target #letter .flip { -webkit-transform: rotateX(180deg); -moz-transform: rotateX(180deg); transform: rotateX(180deg); -webkit-transition-duration: 0.5s; -moz-transition-duration: 0.5s; transition-duration: 0.5s; -webkit-transition-delay: 1s; -moz-transition-delay: 1s; transition-delay: 1s; }letter.js
var aparted = false; $(&#34;#open&#34;).click(function(){ if(!aparted) { var typed = new Typed(&#39;.letter&#39;, { strings: [&#34;^1000Dear&nbsp;&nbsp;Ming&#34;, &#34;M^200ing<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;夜には^300いつも^200寒いよね、^600でも、^600手を^200繋いでいると、^600暖か^200くなるよ!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;どんなに^300寒い夜も、^600君と^300二人でいれば、^600ちっとも^300寒くない!<br><br><p style=&#39;float:right; display:block; width:80px;&#39;>^1000H^200ao</p>&#34;], typeSpeed: 100, backSpeed: 50 }); $(&#39;#open&#39;).find(&#34;span&#34;).eq(0).css(&#39;background-position&#39;, &#34;0 -150px&#34;); aparted = true; var music = document.getElementById(&#39;music2&#39;); if (music.paused) { music.play(); $(&#39;#music_btn2&#39;).css(&#34;opacity&#34;, &#34;1&#34;); } } }); function playPause() { var music = document.getElementById(&#39;music2&#39;); var music_btn = $(&#39;#music_btn2&#39;); if (music.paused){ music.play(); music_btn.css(&#34;opacity&#34;, &#34;1&#34;); } else{ music.pause(); music_btn.css(&#34;opacity&#34;, &#34;0.2&#34;); } } window.onload = function () { var currentUrl = window.location.href; var firstIndex = currentUrl.indexOf(&#34;#&#34;); if (firstIndex <= 0) window.location.href = currentUrl + &#34;#contact&#34;; $(&#39;#music2&#39;).attr(&#39;src&#39;, bgmsrc); document.addEventListener(&#39;touchstart&#39;,function (event) { if(event.touches.length > 1) event.preventDefault(); }); var lastTouchEnd = 0; document.addEventListener(&#39;touchend&#39;,function (event) { var now = (new Date()).getTime(); if(now - lastTouchEnd <= 300) event.preventDefault(); lastTouchEnd = now; }, false); document.addEventListener(&#39;gesturestart&#39;, function (event) { event.preventDefault(); }); $(&#39;body&#39;).css(&#39;opacity&#39;, &#39;1&#39;); $(&#39;#jsi-cherry-container&#39;).css(&#39;z-index&#39;, &#39;-99&#39;); }演示图片
浪漫信封在线演示地址:http://haiyong.site/eluvletter
3D樱花漫天飞舞
HTML 内容
<canvas id=&#34;sakura&#34;></canvas> <div class=&#34;btnbg&#34;> </div> <footer class=&#34;page-footer&#34;> <span>made by </span> <a href=&#34;http://haiyong.site/moyu&#34; target=&#34;_blank&#34;> <img class=&#34;touxiang&#34; src=&#34;http://haiyong.site/wp-content/uploads/2021/07/cropped-59255587-1-192x192.jpg&#34; alt=&#34;George Martsoukos logo&#34;> </a> </footer>CSS 内容
body { padding:0; margin:0; overflow:hidden; height: 600px; } canvas { padding:0; margin:0; } div.btnbg { position:fixed; left:0; top:0; } .page-footer { position: fixed; right: 0; bottom: 20px; display: flex; align-items: center; padding: 5px; color: black; background: rgba(255, 255, 255, 0.65); } .page-footer a { display: flex; margin-left: 4px; } .touxiang{ width:24px; height:24px; }部分 JS 内容
<script id=&#34;sakura_point_vsh&#34; type=&#34;x-shader/x_vertex&#34;> uniform mat4 uProjection; uniform mat4 uModelview; uniform vec3 uResolution; uniform vec3 uOffset; uniform vec3 uDOF; //x:focus distance, y:focus radius, z:max radius uniform vec3 uFade; //x:start distance, y:half distance, z:near fade start attribute vec3 aPosition; attribute vec3 aEuler; attribute vec2 aMisc; //x:size, y:fade varying vec3 pposition; varying float psize; varying float palpha; varying float pdist; //varying mat3 rotMat; varying vec3 normX; varying vec3 normY; varying vec3 normZ; varying vec3 normal; varying float diffuse; varying float specular; varying float rstop; varying float distancefade; void main(void) { // Projection is based on vertical angle vec4 pos = uModelview * vec4(aPosition + uOffset, 1.0); gl_Position = uProjection * pos; gl_PointSize = aMisc.x * uProjection[1][1] / -pos.z * uResolution.y * 0.5; pposition = pos.xyz; psize = aMisc.x; pdist = length(pos.xyz); palpha = smoothstep(0.0, 1.0, (pdist - 0.1) / uFade.z); vec3 elrsn = sin(aEuler); vec3 elrcs = cos(aEuler); mat3 rotx = mat3( 1.0, 0.0, 0.0, 0.0, elrcs.x, elrsn.x, 0.0, -elrsn.x, elrcs.x ); mat3 roty = mat3( elrcs.y, 0.0, -elrsn.y, 0.0, 1.0, 0.0, elrsn.y, 0.0, elrcs.y ); mat3 rotz = mat3( elrcs.z, elrsn.z, 0.0, -elrsn.z, elrcs.z, 0.0, 0.0, 0.0, 1.0 ); mat3 rotmat = rotx * roty * rotz; normal = rotmat[2]; mat3 trrotm = mat3( rotmat[0][0], rotmat[1][0], rotmat[2][0], rotmat[0][1], rotmat[1][1], rotmat[2][1], rotmat[0][2], rotmat[1][2], rotmat[2][2] ); normX = trrotm[0]; normY = trrotm[1]; normZ = trrotm[2]; const vec3 lit = vec3(0.6917144638660746, 0.6917144638660746, -0.20751433915982237); float tmpdfs = dot(lit, normal); if(tmpdfs < 0.0) { normal = -normal; tmpdfs = dot(lit, normal); } diffuse = 0.4 + tmpdfs; vec3 eyev = normalize(-pos.xyz); if(dot(eyev, normal) > 0.0) { vec3 hv = normalize(eyev + lit); specular = pow(max(dot(hv, normal), 0.0), 20.0); } else { specular = 0.0; } rstop = clamp((abs(pdist - uDOF.x) - uDOF.y) / uDOF.z, 0.0, 1.0); rstop = pow(rstop, 0.5); //-0.69315 = ln(0.5) distancefade = min(1.0, exp((uFade.x - pdist) * 0.69315 / uFade.y)); } </script>演示图片
3D樱花漫天飞舞在线演示地址:http://haiyong.site/yinghua
HTML5建造3D樱花漫天飞舞及浪漫信封 [代码]
假如你在复制上述代码时碰到困难,可以经过下面的方式来建立此项目(利用 JavaScript 的 3D樱花漫天飞舞及浪漫信封)
有很多初学者没法将一切这些代码放在一路。对于他们,我已经把一切的代码放在一路了。下方获得源码
希望经过本教程,你也可以利用 HTML5建造3D樱花漫天飞舞及浪漫信封。HTML建造3D樱花漫天飞舞及浪漫信封希望经过本教程,你也可以利用 HTML5建造3D樱花漫天飞舞及浪漫信封。
作者发愤打造一个具有100个小游戏/工具的摸渔网站,更新进度:50/100
我已经写了很长一段时候的技术博客,而且首要经过知乎颁发,这是我的一篇关于若何利用 HTML5建造3D樱花漫天飞舞及浪漫信封。我喜好经过文章分享技术与快乐。你可以拜候我的知乎: https://www.zhihu.com/people/haiyongblog以领会更多信息。希望你们会喜好!
接待大师在批评区提出定见和倡议!
原文地址:https://zhuanlan.zhihu.com/p/446931135
免责声明:
1、文章部分图片源于收集,均为表示图;
2、一切文章、图片、音频视频文件等材料版权归版权一切人一切;
3、因非原创文章及图片等内容没法和版权者联系,如原作者或编辑以为作品不宜上网供阅读,或不应无偿利用,请实时告诉我们,以敏捷采纳适当办法,避免给双方形成不需要的经济损失;
4、本页面内容由爬虫法式自动收集于互联网,如无意中加害了媒体或小我的常识产权,请电邮【E-Mail:cb@yoyodoc.com】告之,我们将于24小时内删除。 |
|