前提・実現したいこと
HTML,CSS,JavaScriptでブラウザ上で文字を浮かび上がらせるサイトを作っています。
http://photoshopvip.net/93415(引用したサイト)
Transmission: Glowing Text Animation(サイトの中で引用したコード)
該当のソースコード
HTML
1<main> 2 <section class="mast"> 3 <figure class="mast__bg" style="background-image:url(https://unsplash.it/1800/800?image=893)"></figure> 4 <header class="mast__header"> 5 <h1 class="mast__title js-spanize">Incoming Transmission</h1> 6 <hr class="sep"/> 7 <p class="mast__text js-spanize"> 8This is a story, all about how, 9My life got twisted upside down. 10So I'd like to tell a story, just sit right there. 11And I'll tell you how I became the prince of Bel Air.</p> 12 13 </header> 14 </section> 15</main>
CSS
1// Config: fonts 2$font-mono: "Cutive Mono", monospace; 3// Config: Ease 4$ease-cb: cubic-bezier(.19,1,.22,1); 5 6//-------------------------- 7// nth-trans-delay() 8// @description: Transition Delay on nth-childs 9// @param: $delay_items: [7] - number of nth-of-type items to create 10// @param: $delay_time:[1.5s] - transition-dealy value 11//-------------------------- 12@mixin nth-trans-delay($delay_items: 7, $delay_time: 0.2s){ 13@for $i from 1 through $delay_items { 14 &:nth-child(#{$i}) { 15 transition-delay: $delay_time * $i; 16 } 17 } 18} 19 20//-------------------------- 21// nth-ani-delay() 22// @description: Animation Delay on nth-childs 23// @param: $delay_items: [7] - number of nth-of-type items to create 24// @param: $delay_time:[1.5s] - transition-dealy value 25//-------------------------- 26@mixin nth-ani-delay($delay_items: 7, $delay_time: 0.2s){ 27@for $i from 1 through $delay_items { 28 &:nth-child(#{$i}) { 29 animation-delay: $delay_time * $i; 30 } 31 } 32} 33//-------------------------- 34// bg-overlay() 35// @description:pseduo overlay element 36// @param: $bg_hex: [$color-dark] - hex value for rgba conversion 37// @param: $bg_opacity:[0.6] - alpha transparency level 38// @param: $top_layer: element or class name for higher z-index layer 39//-------------------------- 40@mixin bg-overlay($bg_hex: #111, $bg_opacity: 0.6, $top_layer: 'header') { 41 &:after { 42 z-index: 0; 43 content: ''; 44 position: absolute; 45 top: 0; 46 left: 0; 47 height: 100%; 48 width: 100%; 49 background: rgba($bg_hex, $bg_opacity); 50 } 51 52 // Layer atop overlay 53 & > #{$top_layer}{ 54 z-index: 2; 55 position: relative; 56 } 57} 58//Setups 59*, *:before, *:after { 60 box-sizing: border-box; 61} 62// Body 63body { 64 margin: 0; 65 width: 100%; 66 font-family: $font-mono; 67 line-height: 1.5; 68 font-weight: 400; 69 font-style: normal; 70 -ms-text-size-adjust: 100%; 71 -webkit-text-size-adjust: 100%; 72 -webkit-font-smoothing: antialiased; 73 -moz-osx-font-smoothing: grayscale; 74 text-rendering: optimizeLegibility; 75} 76 77.sep{ 78 border: 0; 79 width: 3em; 80 height: 1px; 81 margin: 1em 0; 82 background-color: rgba(255,255,255,0.4); 83} 84.mast{ 85 position: relative; 86 display:flex; 87 align-items: center; 88 width: 100%; 89 height: 100vh; 90 color: #fff; 91 background-color: #111; 92 @include bg-overlay(#111, 0.9); 93 94 &__bg{ 95 position: absolute; 96 top: 0; 97 left: 0; 98 width: 100%; 99 height: 100vh; 100 margin: 0; 101 padding: 0; 102 background-size: cover; 103 background-position: 50%; 104 } 105 106 &__header{ 107 padding: 5%; 108 } 109 &__title{ 110 font-family: $font-mono; 111 font-size: 1em; 112 font-weight: 400; 113 letter-spacing: 0.3em; 114 text-transform: uppercase; 115 } 116 // Letter animation 117 &__title span{ 118 animation: letter-glow 0.7s 0s ease both; 119 @include nth-ani-delay(25, 0.05s); 120 } 121 //Letter animation 122 &__text{ 123 font-family: $font-mono; 124 font-size: 1em; 125 margin: 0 0 0.5em; 126 line-height: 1.5; 127 white-space: pre; 128 } 129 130 &__text span{ 131 animation: letter-glow 0.7s 0s ease both; 132 @include nth-ani-delay(180, 0.05s); 133 } 134} 135 136 137// Letter Glow 138@keyframes letter-glow{ 139 0% { opacity: 0; text-shadow: 0px 0px 1px rgba(255,255,255,0.1)} 140 66% { opacity: 1; text-shadow: 0px 0px 20px rgba(255,255,255,0.9) } 141 77% { opacity: 1; } 142 100% { opacity:0.7; text-shadow: 0px 0px 20px rgba(255,255,255,0.0)} 143}
sass
1/*----- 2Spanizer 3- Wraps letters with spans, for css animations 4-----*/ 5(function($) { 6 var s, 7 spanizeLetters = { 8 settings: { 9 letters: $('.js-spanize'), 10 }, 11 init: function() { 12 s = this.settings; 13 this.bindEvents(); 14 }, 15 bindEvents: function(){ 16 s.letters.html(function (i, el) { 17 //spanizeLetters.joinChars(); 18 var spanizer = $.trim(el).split(""); 19 return '<span>' + spanizer.join('</span><span>') + '</span>'; 20 }); 21 }, 22 }; 23 spanizeLetters.init(); 24})(jQuery);
試したこと
拡張子をそれぞれ[.html][.css][.js]にして、これらのファイルを同じ階層に置いたところ、
静的な文字だけが表示され、動きの効果が出てきませんでした。
※[.js]ファイルの最後の行でjQueryを読み込めませんとエラーが出ています。
サイトでは、コピペでできるように言われているのですが、どのようにすればうまく動くのでしょうか?
分かる方、ご教示お願いいたします。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
OS:Windows10
回答1件
あなたの回答
tips
プレビュー