jQuery Colorbox插件
一. Colorbox插件介绍
jQuery Colorbox是一款非常好的内容播放插件。它集弹出层、幻灯片播放功能于一身,不仅于此,它还支持其它的内容格式:例如html, flash, iframe等,这些内容的显示方式都是Ajax的。更难能可贵的是,在压缩后它只有10K的大小,使用这款插件不会给你的网页带来过多的负担,而且还能实现很棒的视觉效果,为用户体验增色不少。
本文已经同步至我的个人博客站点: 积累吧 | jQuery Colorbox插件
Colorbox项目的主页地址是: http://HdhCmsTestjacklmoore测试数据/colorbox
项目主页中提供了5种不同样式的Example:
Example 1: http://HdhCmsTestjacklmoore测试数据/colorbox/example1/
Example 2: http://HdhCmsTestjacklmoore测试数据/colorbox/example2/
Example 3: http://HdhCmsTestjacklmoore测试数据/colorbox/example3/
Example 4: http://HdhCmsTestjacklmoore测试数据/colorbox/example4/
Example 5: http://HdhCmsTestjacklmoore测试数据/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插件的最新版本,您也可以直接点击图片看到效果哦。)
易于使用也是Colorbox的众多优点之一,它的代码调用非常之简洁。
1. 引入jquery和colorbox的js文件
< script src = "https://ajax.googleapis测试数据/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://HdhCmsTestw3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns = "http://HdhCmsTestw3.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测试数据/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项目主页中下载完插件后,打开它,可以看到它的目录结构如下两幅图
这样的目录结构直接放到wordpress下明显不够合理,在当前目录结构下创建一个文件夹colorbox
然后将images文件夹、colorbox.css、jquery.colorbox.js、jquery.colorbox-min.js文件放到colorbox文件夹中
2. 将colorbox文件夹放到主题文件夹下
3. 修改header.php文件
在<head></head>之间添加下面的代码:
< link rel = "stylesheet" href = "http://HdhCmsTestjileiba测试数据/wp-content/themes/h/colorbox/colorbox.css" type = "text/css" media = "screen" />
< script type = "text/javascript" src = "https://ajax.googleapis测试数据/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.
分类: 【2】jQuery & ASP.NET
作者: Leo_wl
出处: http://HdhCmsTestcnblogs测试数据/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于jQuery Colorbox插件的详细内容...