Typecho添加图片暗箱效果
1、引用 FancyBox插件
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!--如果主题已经引用了jQuery库,可以忽略这条-->
<link rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.2/jquery.fancybox.min.css">
<script src="https://cdn.staticfile.org/fancybox/3.5.2/jquery.fancybox.min.js"></script>
2、给文章图片添加标签
找到post.php里的
<?php $this->content(); ?>
替换成
<?php
$pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
$replacement = '<a href="$1" data-fancybox="gallery" /><img src="$1" alt="'.$this->title.'" title="点击放大图片"></a>';
$content = preg_replace($pattern, $replacement, $this->content);
echo $content;
?>
3、在头部或者尾部初始化
<script type="text/javascript">
$(document).ready(function () {
$( ".fancybox").fancybox();
});
</script>
就可以了
打赏采用二维码方式。
非常感谢
我就看一下 反正也学不会 哈哈
其实很简单的,网上找到的最简单粗暴的方法
这么全面的教程,赞一个