Lazy Blocksを使ったカスタムブロックの作り方 (Yes/Noチャート)
今回のカスタムブロックの発想
ベースとなるHTMLを作ってみる
<div class="yesno">
<div class="container">
<section class="slide" id="1">
<div class="upper">
Question
</div>
<div class="middle">
<div style="height: auto;width: 100%;font-size: 100%;">
質問:猫はかわいい?
</div>
<img src="url" class="picture">
</div>
<div class="bottom">
<a href="#2" class="css-button-rounded--black">
Yes
</a>
<a href="#3" class="css-button-rounded--black">
No
</a>
</div>
</section>
</div>
</div>
.yesno {
display: flex;
justify-content: center;
align-items: center;
}
.container {
overflow: auto;
scroll-snap-type: x mandatory;
display: flex;
height: 500px;
width: 500px;
/*IE,Microsoft Edge*/
-ms-overflow-style: none;
/*Firefox*/
scrollbar-width: none;
text-align: center;
color: #ffffff;
font-size: 2rem;
}
/*Google Chrome,Safari*/
.container::-webkit-scrollbar{
display: none;
}
.slide {
scroll-snap-align: center;
height: 500px;
width: 500px;
flex: none;
}
.slide:nth-child(even) {
background-color: #19bee9;
}
.slide:nth-child(odd) {
background-color: #14dab9;;
}
.upper {
height: 10%;
max-height: 10%;
width: 100%;
max-width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.middle {
height: 70%;
max-height: 70%;
width: 100%;
max-width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.bottom {
height: 20%;
max-height: 20%;
width: 100%;
max-width: 100%;
}
.picture {
display: block;
height: inherit;
max-height: inherit;
width: inherit;
max-width: inherit;
object-fit: cover;
margin-top: 16px;
}
/*https://markodenic.com/tools/buttons-generator/*/
.css-button-rounded--black {
/*min-width: 130px;*/
/*height: 40px;*/
font-size: 2rem;
color: #fff;
padding: 5px 10px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
display: inline-block;
outline: none;
border-radius: 5px;
border: 2px solid #212529;
background: #212529;
text-decoration: none;
}
.css-button-rounded--black:hover {
background: #fff;
color: #212529
}
変数の割当・Handlebars実装
<div class="{{blockId}}yesno">
<div class="{{blockId}}container">
{{#each repeater1}}
<section class="{{blockId}}slide" id="{{blockId}}{{math @index '+' 1}}">
<div class="upper">
{{#compare goto1 '>' 0}}
Question {{math @index '+' 1}}
{{/compare}}
</div>
<div class="middle">
<div style="height: auto;width: 100%;font-size: {{font-size}}%;">
{{question}}
</div>
{{#if picture}}
<img src="{{picture.sizes.full.url}}" class="picture">
{{/if}}
</div>
<div class="bottom">
{{#compare goto1 '>' 0}}
<a href="#{{blockId}}{{goto1}}" class="css-button-rounded--black">
{{answer1}}
</a>
<a href="#{{blockId}}{{goto2}}" class="css-button-rounded--black">
{{answer2}}
</a>
{{/compare}}
</div>
</section>
{{/each}}
</div>
</div>
<style>
.{{blockId}}yesno {
display: flex;
justify-content: center;
align-items: center;
}
.{{blockId}}container {
overflow: auto;
/*scroll-snap-type: x mandatory;*/
display: flex;
height: {{slide-y}}px;
width: {{slide-x}}px;
/*IE,Microsoft Edge*/
-ms-overflow-style: none;
/*Firefox*/
scrollbar-width: none;
text-align: center;
color: #fff;
font-size: 2rem;
}
/*Google Chrome,Safari*/
.{{blockId}}container::-webkit-scrollbar{
display: none;
}
.{{blockId}}slide {
scroll-snap-align: center;
height: {{slide-y}}px;
width: {{slide-x}}px;
flex: none;
}
.{{blockId}}slide:nth-child(even) {
background-color: #19bee9;
}
.{{blockId}}slide:nth-child(odd) {
background-color: #14dab9;;
}
.upper {
height: 10%;
max-height: 10%;
width: 100%;
max-width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.middle {
height: 70%;
max-height: 70%;
width: 100%;
max-width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.bottom {
height: 20%;
max-height: 20%;
width: 100%;
max-width: 100%;
}
.picture {
display: block;
height: inherit;
max-height: inherit;
width: inherit;
max-width: inherit;
object-fit: cover;
margin-top: 16px;
}
/*https://markodenic.com/tools/buttons-generator/*/
.css-button-rounded--black {
/*min-width: 130px;*/
/*height: 40px;*/
font-size: 2rem;
color: #fff;
padding: 5px 10px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
display: inline-block;
outline: none;
border-radius: 5px;
border: 2px solid #212529;
background: #212529;
text-decoration: none;
}
.css-button-rounded--black:hover {
background: #fff;
color: #212529
}
</style>
最近のコメント