Skip to content

Shopify 添加尺码表/参数表弹出功能

创建 Page,并命名为:

Size Chart


创建 Snippet,并粘贴代码
size-chart.liquid

<div class="pop-up-modal">
<div class="pop-up-content">
<span class="close-button">&times;</span>
<span class="size-chart-content">{{ pages.size-chart.content }}</span>
</div>
</div>

<script>
const modal = document.querySelector(".pop-up-modal");
const trigger = document.querySelector(".trigger-pop-up");
const closeButton = document.querySelector(".close-button");

function toggleModal() {
modal.classList.toggle("show-pop-up");
}

function windowOnClick(event) {
if (event.target === modal) {
toggleModal();
}
}

trigger.addEventListener("click", toggleModal);
closeButton.addEventListener("click", toggleModal);
window.addEventListener("click", windowOnClick);
</script>

<style>
.pop-up-modal {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
opacity: 0;
display: none;
transform: scale(1.1);
transition: visibility 0s linear 0.25s, opacity 0.25s 0s, transform 0.25s;
}
.pop-up-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 1rem 1.5rem;
width: auto;
border-radius: 0.5rem;
}
.pop-up-content table {
table-layout: auto;
}
.close-button {
float: right;
width: 1.5rem;
line-height: 1.5rem;
text-align: center;
cursor: pointer;
border-radius: 0.25rem;
margin-bottom: 1rem;
}
.close-button:hover {
background-color: darkgray;
}
.show-pop-up {
z-index: 12;
opacity: 1;
display: block;
transform: scale(1.0);
transition: visibility 0s linear 0s, opacity 0.25s 0s, transform 0.25s;
}
.trigger-pop-up {
margin: 15px 0;
width: 100%;
text-decoration: underline;
font-weight: bold;
}
@media only screen and (max-width: 749px) {
.pop-up-content, .size-chart-content table {
width: 100% ;
}
.size-chart-content th, .size-chart-content td {
padding: 10px;
}
}
</style>

 

在 theme.liquid 中 </body> 之前添加以下代码:

{% if request.page_type == 'product' %}
{% if product.options contains 'Size' %}
{% render 'size-chart' %}
{% endif %}
{% endif %}

在加购按钮下方,添加以下代码
{% if product.options contains 'Size' %}
<div class="trigger-pop-up"><a>Size Chart</a></div>
{% endif %}
上一篇文稿 Shopify 多语言自动翻译方案 每月费用不到 3 美金
下一篇文稿 Shopify Theme Kit 下载