WordPress Elementor产品卡片按钮跳转Calendly链接故障求助
解决Elementor中产品卡片按钮打开Calendly预约界面的问题
问题说明
在WordPress Elementor环境中使用Codepen复制的产品卡片代码,已完成颜色等样式调整,但按钮无法实现跳转,需要点击按钮后打开指定的Calendly预约界面。
解决方案
要实现按钮点击唤起Calendly预约弹窗,需对代码做以下调整:
1. 修改产品卡片的按钮代码
将原按钮的空链接替换为触发Calendly弹窗的点击事件:
<div class="card"> <div class="imgBox"> <img src="https://toppng.com/uploads/thumbnail/valorant-11608280122mrhwm6iwqx.png" alt="mouse corsair" class="mouse"> </div> <div class="contentBox"> <h3>Mouse Corsair M65</h3> <h2 class="price">61.<small>98</small> €</h2> <!-- 修改按钮,添加点击事件 --> <a href="javascript:void(0)" class="buy" onclick="openCalendly()">BRONEERI</a> </div> </div>
2. 添加Calendly弹窗触发脚本
在页面中引入Calendly Widget脚本,并添加弹窗初始化函数:
<!-- Calendly Widget脚本 --> <script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js" async></script> <!-- 弹窗触发函数 --> <script> function openCalendly() { Calendly.initPopupWidget({ url: 'https://calendly.com/mokez/neace?hide_gdpr_banner=1' }); return false; } </script>
3. 保留原样式代码
原有的产品卡片样式无需修改,直接保留:
* { margin: 0; padding: 0; font-family: "Istok Web", sans-serif; } .body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #212121; } .card { position: relative; width: 320px; height: 480px; background: #0f1923; border-radius: 20px; overflow: hidden; } .card::before { content: ""; position: absolute; top: -50%; width: 100%; height: 100%; background: #ff4655; transform: skewY(345deg); transition: 0.5s; } .card:hover::before { top: -70%; transform: skewY(390deg); } .card::after { content: "CORSAIR"; position: absolute; bottom: 0; left: 0; font-weight: 600; font-size: 6em; color: rgba(0, 0, 0, 0.1); } .card .imgBox { position: relative; width: 100%; display: flex; justify-content: center; align-items: center; padding-top: 20px; z-index: 1; } .card .contentBox { position: relative; padding: 20px; display: flex; justify-content: center; align-items: center; flex-direction: column; z-index: 2; } .card .contentBox h3 { font-size: 18px; color: white; font-weight: 500; text-transform: uppercase; letter-spacing: 1px; } .card .contentBox .price { font-size: 24px; color: white; font-weight: 700; letter-spacing: 1px; } .card .contentBox .buy { position: relative; top: 100px; opacity: 0; padding: 10px 30px; margin-top: 15px; color: #FFFFFF; text-decoration: none; background: #ff4655; border-radius: 30px; text-transform: uppercase; letter-spacing: 1px; transition: 0.5s; } .card:hover .contentBox .buy { top: 0; opacity: 1; } .mouse { height: 300px; width: auto; }
Elementor使用提示
- 将HTML代码放入Elementor的「HTML」模块中
- 样式代码可放入Elementor的「自定义CSS」区域(或HTML模块的
<style>标签内) - JavaScript代码建议放在HTML模块的末尾,确保Calendly脚本加载完成后再执行
内容的提问来源于stack exchange,提问作者Mokez
相关产品推荐
相关产品推荐

