zoukankan      html  css  js  c++  java
  • jQuery Colorbox插件

    一. Colorbox插件介绍

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

    本文已经同步至我的个人博客站点:积累吧 | jQuery Colorbox插件

    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>
    

    Always keep dream, keep thinking, keep moving, even if the road obstacles , the one more important thing is that always be a pig for you, that's keep fool.

  • 相关阅读:
    为什么重写equals还要重写hashcode?
    谈谈关于Synchronized和lock
    springBoot为啥没有没有web.xml了
    springBoot整合mybatis开发
    springBoot的介绍与搭建
    Java i++原理及i=i++的问题说明
    Django学习笔记〇三——APP以及的文件结构
    Django学习笔记〇二——第一个Django项目
    Django学习笔记〇一——从web的概念引入
    MySQL学习笔记——〇六SQLAlchemy框架
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2519463.html
Copyright © 2011-2022 走看看