轻量级的jQuery lightbox图片插件 ColorBox

JS or jQuery, 转自点点 11 年前 回复

, , , ,

ColorBox 是一个 jQuery Lightbox 插件,轻量级,只有 不到9kb 大小。
支持: 图片,图片群组, slideshow, ajax, inline, 和iframe.
使用方法:
点击下载ColorBox插件,然后将 jquery.colorbox-min.js 和 CSS文件放上去(有4中样式,自己爱好选择)

<link media="screen" rel="stylesheet" href="colorbox.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="../colorbox/jquery.colorbox.js"></script>
<script language="javascript">
$(document).ready(function(){
   $("a[rel='colorbox']").colorbox();// rel='colorbox' 加上ColorBox 效果
   $("#content a[rel='nofollow']").colorbox({width:"75%", height:"85%", iframe:true});//  nofollow属性的网址加上ColorBox 效果
            });
</script>

然后将下面代码复制到  functions.php 文件中:

function colorbox ($content)
{   global $post;
    $pattern = "/<a (.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)< \/a>/i";
    $replacement = '</a><a $1href=$2$3.$4$5 rel="colorbox" $6>$7</a>';
    $content = preg_replace($pattern, $replacement, $content);
    return $content;
}
add_filter('the_content', 'colorbox'); //所有图片 加上一个 rel="colorbox"

View Demo:
demo1
demo2
demo3
demo4
demo5
Via:http://mengqing.org/archives/jquery-colorbox.html

支付宝打赏微信打赏

如果此文对你有帮助,欢迎打赏作者。

发表评论

欢迎回来 (打开)

(必填)