Typecho Fancybox 给文章图片添加灯箱效果

2024-02-15T22:54:00+08:00 | 1 分钟阅读 | 更新于 2024-02-15T22:54:00+08:00

hehe

Typecho Fancybox 给文章图片添加灯箱效果

介绍
FancyBox是一款优秀的弹出框Jquery插件,FancyBox提供了一种简洁优雅的方式去为图片、网页和多媒体添加灯箱功能。此教程为大家介绍 FancyBox在Typecho主题上的应用。

下面开始教程~

引用 FancyBox插件
把下面内容添加到 header.php 中 前面

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.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>

修改post.php
打开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;
?>

初始化FancyBox
把下面js添加到 footer.php 文件的

<script type="text/javascript">
    $(document).ready(function () {
        $( ".fancybox").fancybox();
    });
</script>
comments powered by Disqus

© 2024 和和日志

🌱 Powered by Hugo with theme Dream.

关于我

Hi…🐟 everyone! I’m Hehe. I’m passionate about computers and the internet, my hobby is playing pool, and I have a >special fondness for games. In the field of computers, I enjoy constantly learning new technologies. Pool is my >way of relieving stress, and gaming is a way for me to interact with friends. I like making new friends, so if you >share these interests, let’s connect and exchange experiences!

2024 年 07 月 19 日更新。

关于留言评论

本博客评论系统用的是 Disqus,如果您要留言 请登录👉 github后进行留言讨论~

赞助我(Sponsor Me)

If you like my works or find them helpful, please consider buying me a cup of coffee ☕️. It inspires me to create and maintain more projects in the future. 🦾

👉 Buy me a coffee

知识共享(Creative Commons)

此网站的所有内容都遵循 CC BY-NC-SA 4.0

社交链接