jQuery Colorbox插件

一. Colorbox插件介绍

jQuery Colorbox是一款非常好的内容播放插件。它集弹出层、幻灯片播放功能于一身,不仅于此,它还支持其它的内容格式:例如html, flash, iframe等,这些内容的显示方式都是Ajax的。更难能可贵的是,在压缩后它只有10K的大小,使用这款插件不会给你的网页带来过多的负担,而且还能实现很棒的视觉效果,为用户体验增色不少。

Colorbox项目的主页地址是:http://www.jacklmoore.com/colorbox
项目主页中提供了5种不同样式的Example:

Example 1:http://www.jacklmoore.com/colorbox/example1/
Example 2:http://www.jacklmoore.com/colorbox/example2/
Example 3:http://www.jacklmoore.com/colorbox/example3/
Example 4:http://www.jacklmoore.com/colorbox/example4/
Example 5:http://www.jacklmoore.com/colorbox/example5/

每一个Example中都提供了以下效果:

  • Elastic Transition(弹性动画)
  • Fade Transition(淡入淡出动画)
  • No transition + fixed width and height  75% of screen size (无动画,宽高以屏幕的75%自适应)
  • Slideshow(幻灯片播放)
  • Other Content Types (其它类型:外部html, flash和视频,iframe的flash和视频,iframe的外部html,内部html)

二. Colorbox插件使用

在使用colorbox之前,先看看基本的效果图吧。(本博客已经使用了colorbox插件的最新版本,您也可以直接点击图片看到效果哦。)

image

易于使用也是Colorbox的众多优点之一,它的代码调用非常之简洁。

1. 引入jquery和colorbox的js文件

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="colorbox/jquery.colorbox.js"></script>

2. 引入colorbox的css文件

<link media="screen" rel="stylesheet" href="colorbox\colorbox.css" />

3. html代码

<body>
        <h1>ColorBox演示</h1>

        <h2>弹性效果</h2>
        <p><a class="group1" data-rel='hi' href="../content/ohoopee1.jpg" title="Me and my grandfather on the Ohoopee.">Grouped Photo 1</a></p>
        <p><a class="group1" href="../content/ohoopee2.jpg" title="On the Ohoopee as a child">Grouped Photo 2</a></p>
        <p><a class="group1" href="../content/ohoopee3.jpg" title="On the Ohoopee as an adult">Grouped Photo 3</a></p>
    </body>

4. 调用colorbox的代码

<script>
    $(document).ready(function(){
        //元素调用Colorbox的示例
        $(".group1").colorbox({ rel: 'group1' });
    });
</script>

5. 最简单示例的完整代码

以上是如何使用的每一个步骤,这里是对上面4个步骤的整合后的完整示例。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>ColorBox 示例</title>
        <link rel="stylesheet" href="colorbox/colorbox.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script src="colorbox/jquery.colorbox.js"></script>
<script>
    $(document).ready(function(){
        //元素调用Colorbox的示例
        $(".group1").colorbox({ rel: 'group1' });
    });
</script>
    </head>
    <body>
        <h1>ColorBox演示</h1>

        <h2>弹性效果</h2>
        <p><a class="group1" data-rel='hi' href="../content/ohoopee1.jpg" title="Me and my grandfather on the Ohoopee.">Grouped Photo 1</a></p>
        <p><a class="group1" href="../content/ohoopee2.jpg" title="On the Ohoopee as a child">Grouped Photo 2</a></p>
        <p><a class="group1" href="../content/ohoopee3.jpg" title="On the Ohoopee as an adult">Grouped Photo 3</a></p>
    </body>
</html>


三、将它整合到Wordpress中

众多使用wordpress的朋友可能比较关心如何将colorbox插件整合到wordpress中去,而不需要到wordpress官方网站上搜索这类插件去安装。

1. 目录结构变更

在colorbox项目主页中下载完插件后,打开它,可以看到它的目录结构如下两幅图

image

image

这样的目录结构直接放到wordpress下明显不够合理,在当前目录结构下创建一个文件夹colorbox

image

然后将images文件夹、colorbox.css、jquery.colorbox.js、jquery.colorbox-min.js文件放到colorbox文件夹中

image

2. 将colorbox文件夹放到主题文件夹下

image

3. 修改header.php文件

在<head></head>之间添加下面的代码:

<link rel="stylesheet" href="http://www.jileiba.com/wp-content/themes/h/colorbox/colorbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/colorbox/jquery.colorbox-min.js"></script>
<script type="text/javascript">
    jQuery(function ($) {
        $("a[rel=ignition]").colorbox({ rel: 'ignition' });
    });
</script>

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值