HTML 結構
<div class="toolbarframe" style="display:none;">
<a href="https://example.com" target="_blank">
<img src="/upfile/swf/s.jpg" alt="廣告圖片" />
</a>
<a class="bigad_close" href="javascript:;">關閉</a>
</div>
jQuery 控制邏輯
$(function() {
// 3 秒後淡入
setTimeout(function() { $(".toolbarframe").fadeIn("slow"); }, 3000);
// 13 秒後淡出
setTimeout(function() { $(".toolbarframe").fadeOut("slow"); }, 13000);
// 手動關閉
$(".bigad_close").on("click", function() {
$(".toolbarframe").fadeOut("slow");
});
});
進階:避免重複彈出(使用 Cookie/LocalStorage)
$(function() {
if (localStorage.getItem("adShown")) return; // 已看過不再彈出
setTimeout(function() {
$(".toolbarframe").fadeIn("slow");
localStorage.setItem("adShown", "1");
}, 3000);
setTimeout(function() { $(".toolbarframe").fadeOut("slow"); }, 13000);
$(".bigad_close").on("click", function() {
$(".toolbarframe").fadeOut("slow");
});
});
CSS 建議
.toolbarframe {
position: fixed; right: 20px; bottom: 20px;
z-index: 9999; background: #fff; border: 1px solid #ddd;
box-shadow: 0 2px 8px rgba(0,0,0,.2); padding: 10px;
}
.bigad_close { display: block; text-align: right; color: #666; cursor: pointer; margin-top: 5px; }