HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/9-1-1.css">
body内のスクロールダウンアイコンを表示させたい場所にHTMLを記載します。
<div class="scrolldown1"><span>Scroll</span></div>
CSSの書き方
/*====== 9-1-1 縦線が動いてスクロールを促す =======*/
/*スクロールダウン全体の場所*/
.scrolldown1{
/*描画位置※位置は適宜調整してください*/
position:absolute;
left:50%;
bottom:10px;
/*全体の高さ*/
height:50px;
}
/*Scrollテキストの描写*/
.scrolldown1 span{
/*描画位置*/
position: absolute;
left:-15px;
top: -15px;
/*テキストの形状*/
color: #eee;
font-size: 0.7rem;
letter-spacing: 0.05em;
}
/* 線の描写 */
.scrolldown1::after{
content: "";
/*描画位置*/
position: absolute;
top: 0;
/*線の形状*/
width: 1px;
height: 30px;
background: #eee;
/*線の動き1.4秒かけて動く。永遠にループ*/
animation: pathmove 1.4s ease-in-out infinite;
opacity:0;
}
/*高さ・位置・透過が変化して線が上から下に動く*/
@keyframes pathmove{
0%{
height:0;
top:0;
opacity: 0;
}
30%{
height:30px;
opacity: 1;
}
100%{
height:0;
top:50px;
opacity: 0;
}
}
HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/7-2-3.css">
body内の検索窓を表示させたい場所にHTMLを記載します。
<div class="open-btn"></div><!--開閉ボタン-->
<div id="search-wrap"><!--表示エリアのHTML開閉ボタンをクリックするたび、search-wrap に表示用のクラス名が付与・除去されて付与の場合出現します。-->
<form role="search" method="get" id="searchform" action="">
<input type="text" value="" name="" id="search-text" placeholder="search">
<input type="submit" id="searchsubmit" value="">
</form>
<!--/search-wrap--></div>
body 終了タグ直前に jQuery、動きを制御する自作のJS の2つを読み込みます。
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!--自作のJS-->
<script src="js/7-2-3.js"></script>
CSSの書き方
/*========= 検索窓を開くためのボタン設定 ===========*/
.open-btn{
position: absolute;
top:10px;
right:10px;
background:url("../img/icon_search.svg") no-repeat 15px center;/*虫眼鏡アイコンを背景に表示*/
background-size: 20px 20px;
width:50px;
height:50px;
cursor: pointer;/*カーソルを指マークに*/
}
/*クリック後、JSでボタンに btnactive クラスが付与された後の見た目*/
.open-btn.btnactive{
background:url("../img/icon_close.svg") no-repeat 15px center;/*閉じるアイコンを背景に表示*/
background-size: 18px 18px;
}
/*========= 検索窓の設定 ===============*/
/*==検索窓背景のエリア*/
#search-wrap{
position:absolute;/*絶対配置にして*/
top:150px;
right:20px;
z-index: -1;/*最背面に設定*/
opacity: 0;/*透過を0に*/
width:0;/*横幅は0に*/
transition: all 0.4s;/*transitionを使ってスムースに現れる*/
border-radius: 5px;
}
/*ボタンクリック後、JSで#search-wrapに panelactive クラスが付与された後の見た目*/
#search-wrap.panelactive{
opacity: 1;/*不透明に変更*/
z-index: 3;/*全面に出現*/
width:280px;
padding:20px;
top:60px;
background:#fff;
}
/*==検索窓*/
#search-wrap #searchform{
display: none;/*検索窓は、はじめ非表示*/
}
/*ボタンクリック後、JSで#search-wrapに panelactive クラスが付与された後*/
#search-wrap.panelactive #searchform{
display: block;/*検索窓を表示*/
}
/*==検索フォームの設定*/
/*==テキスト入力とボタンinput共通設定*/
#search-wrap input{
-webkit-appearance:none;/*SafariやChromeのデフォルトの設定を無効*/
outline: none;
cursor: pointer;/*カーソルを指マークに*/
color: #666;
}
/*テキスト入力input設定*/
#search-wrap input[type="text"] {
width: 100%;
border: none;
border-bottom:2px solid #ccc;
transition: all 0.5s;
letter-spacing: 0.05em;
height:46px;
padding: 10px;
}
/*テキスト入力inputにフォーカスされたら*/
#search-wrap input[type="text"]:focus {
background:#eee;/*背景色を付ける*/
}
/*ボタンinput設定*/
#search-wrap input[type="submit"] {
position: absolute;
top:10px;
right:30px;
background:url("../img/icon_search.svg") no-repeat right;/*虫眼鏡アイコンを背景に表示*/
background-size: 20px 20px;
width:30px;
height: 60px;
}
JSの書き方
//開閉ボタンを押した時には
$(".open-btn").click(function () {
$(this).toggleClass('btnactive');//.open-btnは、クリックごとにbtnactiveクラスを付与&除去。1回目のクリック時は付与
$("#search-wrap").toggleClass('panelactive');//#search-wrapへpanelactiveクラスを付与
$('#search-text').focus();//テキスト入力のinputにフォーカス
});
HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/7-2-2.css">
body内のスライドを表示させたい場所にHTMLを記載します。
<div class="open-btn"></div><!--虫眼鏡マークのHTML-->
<div id="search-wrap"><!--表示エリアのHTML虫眼鏡マークをクリックするとsearch-wrap に表示用のクラス名が付与されて前面に画面表示。閉じるボタン(close-btn)をクリックするとクラス名が除去されて非表示。-->
<div class="close-btn"><span></span><span></span></div>
<div class="search-area">
<form role="search" method="get" action="">
<input type="text" value="" name="" id="search-text" placeholder="search">
<input type="submit" id="searchsubmit" value="">
</form>
<!--/search-area--></div>
<!--/search-wrap--></div>
body 終了タグ直前に jQuery、動きを制御する自作のJS の2つを読み込みます。
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!--自作のJS-->
<script src="js/7-2-2.js"></script>
CSSの書き方
/*========= 検索窓を開くための虫眼鏡ボタン設定 ===========*/
.open-btn{
position: absolute;
top:10px;
right:10px;
background:#fff url("../img/icon_search.svg") no-repeat 15px center;/*虫眼鏡アイコンを背景に表示*/
background-size: 20px 20px;
width:50px;
height:50px;
border-radius: 50%;
cursor: pointer;
}
/*========= 検索窓の設定 ===============*/
/*==検索窓背景のエリア*/
#search-wrap{
position:fixed;/*固定配置にして*/
top: 0;
left: 0;
z-index: -1;/*最背面に設定*/
opacity: 0;/*透過を0に*/
transition: all 0.4s;/*transitionを使ってスムースに現れる*/
width:100%;
height: 100vh;
}
/*ボタンクリック後、JSで#search-wrapに panelactive クラスが付与された後の見た目*/
#search-wrap.panelactive{
opacity: 1;/*不透明に変更*/
z-index: 3;/*全面に出現*/
background:#333;
/*中の要素を天地中央揃えにする設定*/
display: flex;
justify-content: center;
align-items: center;
}
/*==検索窓のエリア*/
#search-wrap .search-area{
display: none;/*検索窓のエリアは、はじめ非表示*/
}
/*ボタンクリック後、JSで#search-wrapに panelactive クラスが付与された後*/
#search-wrap.panelactive .search-area{
display: block;/*検索窓エリアを表示*/
width:80%;
position: relative;
}
/*==検索フォームの設定*/
#search-wrap form{
position: relative;
height: 66px;
}
/*==テキスト入力とボタンinput共通設定*/
#search-wrap input{
-webkit-appearance:none;/*SafariやChromeのデフォルトの設定を無効*/
outline: none;
cursor: pointer;/*カーソルを指マークに*/
color: #fff;
}
/*テキスト入力input設定*/
#search-wrap input[type="text"] {
width: 100%;
padding: 20px;
border: none;
border-bottom:2px solid #666;
transition: all 0.5s;
letter-spacing: 0.05em;
}
#search-wrap input[type="text"]:focus {
background:#444;
}
/*ボタンinput設定*/
#search-wrap input[type="submit"] {
position: absolute;
top:0;
right:10px;
background:url("../img/icon_search.svg") no-repeat 15px center;/*虫眼鏡アイコンを背景に表示*/
background-size: 25px 25px;
width:60px;
height: 60px;
}
/*======= 閉じるための×ボタン ========*/
.close-btn{
position: absolute;
top:10px;
right:10px;
z-index: 2;
cursor: pointer;
width: 60px;
height:60px;
}
.close-btn span{
display: inline-block;
position: absolute;
left: 14px;
height: 3px;
border-radius: 2px;
background-color: #fff;
}
/*×マーク*/
.close-btn span:nth-of-type(1) {
top: 21px;
left: 16px;
transform: translateY(6px) rotate(-135deg);
width: 50%;
}
.close-btn span:nth-of-type(2){
top: 32px;
left: 16px;
transform: translateY(-6px) rotate(135deg);
width: 50%;
}
JSの書き方
//開くボタンを押した時には
$(".open-btn").click(function () {
$("#search-wrap").addClass('panelactive');//#search-wrapへpanelactiveクラスを付与
$('#search-text').focus();//テキスト入力のinputにフォーカス
});
//閉じるボタンを押した時には
$(".close-btn").click(function () {
$("#search-wrap").removeClass('panelactive');//#search-wrapからpanelactiveクラスを除去
});
HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/7-2-1.css">
body内の検索窓を表示させたい場所にHTMLを記載します。
<div id="search-wrap">
<form role="search" method="get" action="">
<input type="text" value="" name="" id="search-text">
</form>
<!--/search-wrap--></div>
CSSの書き方
/*========= 検索窓のためのCSS ===============*/
/*検索窓のエリア*/
#search-wrap {
position: absolute;/*絶対配置にして*/
z-index: 2;/*最前面に設定。数字は変更可*/
top:10px;
right:10px;
}
/*テキスト入力input設定*/
#search-text{
-webkit-appearance:none;/*SafariやChromeのデフォルトの設定を無効*/
width: 60px;/*テキスト入力エリアが伸びる前の横幅*/
height: 60px;
padding: 20px;
border: none;
background:#fff url("../img/icon_search.svg") no-repeat 17px center;/*虫眼鏡アイコンを背景に表示*/
background-size: 25px 25px;
transition: all 0.5s;/*transitionを使ってスムースに伸ばす*/
outline: none;
cursor: pointer;/*カーソルを指マークに*/
}
/*テキスト入力inputにフォーカスした時の形状*/
#search-text:focus {
width: 250px;/*テキスト入力エリアが伸びる後の横幅*/
padding: 20px 0 20px 60px;
box-shadow: 0 2px rgba(6,0,1,.26);
}
HTMLの書き方
head終了タグ直前に自作のCSSを読み込みます。
<link rel="stylesheet" type="text/css" href="css/6-3-2.css">
body内の背景動画を表示させたい場所にHTMLを記載します。
<header id="header">
<div id="loading">Loading...</div>
<div id="youtube-area">
<h1>Title</h1>
<div id="youtube"></div><!--youtube表示エリア-->
<div id="youtube-mask"></div><!--youtubeマスクエリア-->
</div>
</header>
<div id="container">
<p>ここに下のコンテンツが入ります</p>
<!--/container--></div>
body 終了タグ直前に jQuery、動きを制御する自作のJS の2 つを読み込みます。
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!--自作のJS-->
<script src="js/6-3-2.js"></script>
CSSの書き方
/*========= 背景動画設定のCSS ===============*/
/*header設定*/
#header{
position: relative;/*ローディング画像などを表示す際の基点とするため指定*/
height: 100vh;/*高さを全画面にあわせる*/
text-align: center;
color: #fff;
/*ローディング画面時&動画が表示されないときに表示する背景画像のレスポンシブ化*/
background: url("../img/movie.jpg") no-repeat;
background-size: cover;
}
/* ローディングアイコン設定 */
#loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-weight: bold;
}
/*jQueryで付与されたdisappearクラスがついたらロゴエリアを非表示*/
#loading.disappear{
display: none;
}
/* youtube設定 */
#youtube-area{
position: fixed;
z-index: 1;/*最背面に設定*/
top: 0;
right:0;
left:0;
bottom:0;
overflow: hidden;
opacity: 0;
}
/*jQueryで付与されたappearクラスがついたらYoutubeエリアをふわっと表示*/
#youtube-area.appear {
animation-name:PageAnimeAppear;
animation-duration:.5s;
animation-fill-mode:forwards;
}
@keyframes PageAnimeAppear{
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#youtube {
/*天地中央配置*/
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/*縦横幅指定*/
width: 177.77777778vh; /* 16:9 の幅→16 ÷ 9= 177.77% */
height: 56.25vw; /* 16:9の幅 → 9 ÷ 16 = 56.25% */
min-height: 100%;
min-width: 100%;
}
/*youtubeがクリックされないためのマスク*/
#youtube-mask{
position: absolute;
z-index: 2;/*下から2番目に表示*/
top:0;
width:100%;
height: 100%;
}
/*youtube 上のロゴ */
h1{
position:absolute;
z-index: 2;/*下から2番目に表示*/
/*天地中央配置*/
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
/*色指定*/
color:#fff;
text-shadow: 0 0 15px #666;
}
/*下のコンテンツ*/
#container{
position: relative;/*relativeを指定してfixed指定をした#youtube-areaの上に表示*/
z-index: 3;/*一番上に表示*/
/*見た目の調整*/
background:#333;
color: #fff;
padding:300px 0;
text-align: center;
}
JSの書き方
//ローディング画面
$(window).on('load',function(){
$("#youtube-area").addClass('appear');
$("#loading").addClass('disappear');
});
//youtube API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var ytPlayer;
function onYouTubeIframeAPIReady() {
ytPlayer = new YT.Player('youtube', {//動画を表示させたいIDを指定
videoId: 'Kq95zgCrxeY',//動画のアドレスの指定
playerVars: {
playsinline: 1,// インライン再生を行う
autoplay:1,//自動再生を行う
fs:0,//全画面表示ボタンを表示しない
rel: 0,// 再生中の動画と同じチャンネルの関連動画を表示
controls: 0,// プレーヤー コントロールを表示しない
modestbranding: 1, // YouTubeロゴの非表示
iv_load_policy: 3, // アノテーションの非表示
start:50,//50秒後から動画がスタート
},
events: {// イベント
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
//ミュートにしてから再生する設定
function onPlayerReady(event) {
event.target.mute();
event.target.playVideo();
}
//ループ設定
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
event.target.playVideo();
}
}