添加fancybox灯箱代码,需要添加依赖的jquery库。
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css"/>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/fancybox.umd.js"></script>
<script>
$(function () {
$('.post-content').find('img').each(function () {
var _this = $(this);
var _src = _this.attr("src");
var _alt = _this.attr("alt");
_this.wrap('<a data-fancybox="images" href="' + _src + '" data-caption="' + _alt + '"></a>');
})
})
</script>
其中,$('.post-content') 改为自己的文章页面的类名。
评论0
暂时没有评论