START
Q1
質問が入ります質問が入ります
質問が入ります
NEXT
Q2
質問が入ります質問が入ります
FINISH
Q3
質問が入ります質問が入ります
アンケートへのご回答
ありがとうございました!
下記Beyondコード
JS head
<!-- タグ設定のJavaScript headに以下をカットして貼り付けてください。
同一widgetを複数追加する場合、複数回貼付けは不要です。 -->
<script>
var questionAdvice = questionAdvice || {};
(function(_) {
const target = '.js-question';
_.questionCheck = function(el) {
let advice;
let checkItems = el.querySelectorAll('.js-item');
checkItems.forEach(checkItem => {
checkItem.addEventListener('change', (e) => {
advice = e.target.closest('.js-question').querySelector('.js-advice');
if (advice.classList.contains('is-hidden')) {
advice.classList.remove('is-hidden');
smoothScroll(advice)
}
})
});
function smoothScroll(target) {
let elPos = target.getBoundingClientRect().top;
let offset = window.pageYOffset;
let pos = elPos + offset;
window.scrollTo({
top: pos,
behavior: 'smooth',
});
};
};
/**
* Lazyload画像の読み込みチェック
* @param {object} object チェックしたい画像
* @param {callback} callback ロード完了時に実行する関数
*
*/
_.lazyImgLoaded = function(object, callback) {
if (typeof LazyLoad === 'undefined' || !(object.length)) {
if (!callback) return;
callback();
return;
}
const target = Array.from(object);
const promise = target.map(async (img) => {
return imgCheck(img);
});
Promise.all(promise).then((msg) => {
if (!callback) return;
callback();
});
function imgCheck(img) {
let flg = img.classList.contains('loaded');
return new Promise((resolve, reject) => {
if (flg) {
resolve("OK");
return;
} else {
LazyLoad.load(img, {
callback_loaded: resolve("OK"),
callback_cancel: reject("ERROR"),
callback_error: reject("ERROR")
}); //画像の読み込み
}
});
}
};
_.init = function() {
Array.from(document.querySelectorAll(target), el => {
_.questionCheck(el);
})
};
})(questionAdvice);
</script>
<!-- JavaScript headここまで -->
<!-- タグ設定のJavaScript bodyに以下をカットして貼り付けてください。
同一widgetを複数追加する場合、複数回貼付けは不要です。 -->
<script>
document.addEventListener('DOMContentLoaded', function() {
questionAdvice.lazyImgLoaded(document.querySelectorAll(".js-question img"), questionAdvice.init);
}, false);
</script>
<!-- JavaScript bodyここまで -->
HTML
<div class="questionCheck__area">
<div class="questionCheck__head">
<img src="https://production.static.squadbeyond.com/uploads/article_photo/photo/711633/2856f88e-0076-4f7a-9dd6-c1e5117bb18b.png" alt="" height="380" width="570" draggable="false">
</div>
<div class="questionCheck__inner">
<div class="arrow">
<span class="arrowInTxt">START</span>
</div>
<div class="question__box js-question">
<div class="question__head">
<p class="num">Q1</p>
<p class="txt">質問が入ります質問が入ります<br>質問が入ります</p>
</div>
<div class="question__items">
<input class="js-item" type="radio" name="q1" id="q1-1">
<label for="q1-1">選択肢1-1</label>
<input class="js-item" type="radio" name="q1" id="q1-2">
<label for="q1-2">選択肢1-2</label>
<input class="js-item" type="radio" name="q1" id="q1-3">
<label for="q1-3">選択肢1-3</label>
<input class="js-item" type="radio" name="q1" id="q1-4">
<label for="q1-4">選択肢1-4</label>
</div>
<div class="advice__box js-advice is-hidden">
<img src="https://production.static.squadbeyond.com/uploads/article_photo/photo/711633/2856f88e-0076-4f7a-9dd6-c1e5117bb18b.png" alt="" draggable="false">
</div>
</div>
<div class="arrow">
<span class="arrowInTxt">NEXT</span>
</div>
<div class="question__box js-question">
<div class="question__head">
<p class="num">Q2</p>
<p class="txt">質問が入ります質問が入ります</p>
</div>
<div class="question__items">
<input class="js-item" type="radio" name="q2" id="q2-1">
<label for="q2-1">選択肢2-1</label>
<input class="js-item" type="radio" name="q2" id="q2-2">
<label for="q2-2">選択肢2-2</label>
<input class="js-item" type="radio" name="q2" id="q2-3">
<label for="q2-3">選択肢2-3</label>
<input class="js-item" type="radio" name="q2" id="q2-4">
<label for="q2-4">選択肢2-4</label>
</div>
<div class="advice__box js-advice is-hidden">
<img src="https://production.static.squadbeyond.com/uploads/article_photo/photo/711633/2856f88e-0076-4f7a-9dd6-c1e5117bb18b.png" alt="" draggable="false">
</div>
</div>
<div class="arrow">
<span class="arrowInTxt">FINISH</span>
</div>
<div class="question__box js-question">
<div class="question__head">
<p class="num">Q3</p>
<p class="txt">質問が入ります質問が入ります</p>
</div>
<div class="question__items">
<input class="js-item" type="radio" name="q3" id="q3-1">
<label for="q3-1">選択肢3-1</label>
<input class="js-item" type="radio" name="q3" id="q3-2">
<label for="q3-2">選択肢3-2</label>
<input class="js-item" type="radio" name="q3" id="q3-3">
<label for="q3-3">選択肢3-3</label>
<input class="js-item" type="radio" name="q3" id="q3-4">
<label for="q3-4">選択肢3-4</label>
</div>
<div class="advice__box js-advice is-hidden">
<img src="https://production.static.squadbeyond.com/uploads/article_photo/photo/711633/2856f88e-0076-4f7a-9dd6-c1e5117bb18b.png" alt="" draggable="false">
</div>
</div>
<div class="thanks__box">
<div class="thanks__head">
<div class="baloon__box">
<p class="txt">アンケートへのご回答<br>ありがとうございました!</p>
</div>
</div>
<div class="thanks__content">
<img src="https://production.static.squadbeyond.com/uploads/article_photo/photo/711633/2856f88e-0076-4f7a-9dd6-c1e5117bb18b.png" alt="" height="342" width="513" draggable="false">
<a href="○○○○○" class="btn" draggable="false">○○○○の<br>予約はこちら</a>
</div>
</div>
</div>
</div>
CSS
p {
margin: 0;
}
.questionCheck__area {
width: 100%;
height: auto;
}
.questionCheck__area img {
width: 100%;
height: auto;
}
.questionCheck__area .arrow {
width: 0;
height: 0;
border-style: solid;
border-right: 100px solid transparent;
border-left: 100px solid transparent;
border-top: 60px solid #95dfd6;
border-bottom: 0;
position: relative;
margin: 20px auto 0;
}
.arrow .arrowInTxt {
position: absolute;
top: -50px;
left: 50%;
transform: translateX(-50%);
font-size: 16px;
font-weight: bold;
color: #fff;
max-width: initial;
}
.question__box {
margin-top: 20px;
width: 100%;
}
.question__box .question__head {
width: 95%;
margin: 0 auto;
display: flex;
justify-content: flex-start;
align-items: flex-start;
}
.question__box .question__head .num {
width: 100px;
height: 100px;
border-radius: 50px;
background: #F3C759;
color: #fff;
font-size: 40px;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
}
@media screen and (max-width:600px) {
.question__box .question__head .num {
width: 80px;
height: 80px;
border-radius: 40px;
font-size: 30px;
}
}
.question__box .question__head .txt {
width: calc(100% - 120px);
margin-left: 20px;
font-size: 32px;
font-weight: bold;
color: #666;
}
@media screen and (max-width:600px) {
.question__box .question__head .txt {
width: calc(100% - 90px);
margin-left: 10px;
font-size: 24px;
}
}
.question__box .question__items {
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
margin-top: 10px;
}
.question__items input {
display: none;
}
.question__items label {
width: calc(90% - 80px);
padding: 10px 15px 10px 65px;
margin: 15px auto 0;
border-radius: 5px;
background: #99CFE5;
color: #fff;
font-size: 30px;
position: relative;
}
@media screen and (max-width:600px) {
.question__items label {
font-size: 24px;
}
}
.question__items input:checked+label {
background: #44A5CB;
}
.question__items label:before {
content: '';
width: 30px;
height: 30px;
border: 2px solid #fff;
position: absolute;
top: 50%;
left: 15px;
transform: translateY(-50%);
}
.question__items input:checked+label:after {
content: '';
width: 16px;
height: 6px;
display: block;
border-bottom: 5px solid #fff;
border-left: 5px solid #fff;
position: absolute;
top: 45%;
left: 25px;
transform: rotate(-40deg) translateY(-45%);
}
.advice__box {
margin-top: 60px;
}
.thanks__box {
width: 90%;
margin: 60px auto 0;
}
.thanks__box .thanks__head .baloon__box {
width: calc(100% - 20px);
background: #95dfd6;
text-align: center;
font-size: 30px;
color: #fff;
border-radius: 5px;
padding: 10px;
margin-bottom: 30px;
position: relative;
}
@media screen and (max-width:600px) {
.thanks__box .thanks__head .baloon__box {
font-size: 24px;
}
}
.thanks__box .thanks__head .baloon__box:after {
content: '';
width: 0;
height: 0;
border-style: solid;
border-right: 10px solid transparent;
border-left: 10px solid transparent;
border-top: 15px solid #95dfd6;
position: absolute;
bottom: -15px;
left: 50%;
transform: translateX(-50%);
}
.thanks__content {
width: 100%;
margin-top: 30px;
}
.thanks__content .btn {
width: 100%;
height: auto;
padding: 20px 0;
margin-top: 20px;
border-radius: 20vw;
background-image: linear-gradient(to top, #f83600 0%, #f9d423 100%);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
display: inline-block;
color: #fff;
font-size: 24px;
font-weight: bold;
text-align: center;
text-decoration: none;
transition: opacity 0.2s;
opacity: 1;
}
.thanks__content .btn:hover {
opacity: 0.8;
}
.is-hidden {
display: none;
}