欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery图片播放浏览插件prettyPhoto使用详解

程序员文章站 2022-06-07 14:40:59
一、prettyphoto简介 prettyphoto是一款基于jquery的轻量级的lightbox图片播放浏览插件,它不仅支持图片,还同时支持视频、flash、youtu...

一、prettyphoto简介

jquery图片播放浏览插件prettyPhoto使用详解

prettyphoto是一款基于jquery的轻量级的lightbox图片播放浏览插件,它不仅支持图片,还同时支持视频、flash、youtube、iframe和ajax。而且prettyphoto配置和使用都十分简单,扩展性也不错,你可以最大限度地自定义prettyphoto。目前,prettyphoto兼容大部分主流的,包括令人纠结的ie6。

prettyphoto插件的项目地址:https://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

建议英文好的朋友直接去官网上了解这个插件的用法,如果你的英文很烂,那么也别急,下面我就给大家来一一介绍prettyphoto的使用方法。

二、prettyphoto使用方法介绍

1、引入jquery核心库和prettyphoto插件库以及prettyphoto样式表文件

 

代码如下:


<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="css/prettyphoto.css" type="text/css" media="screen" charset="utf-8" />
<script src="js/jquery.prettyphoto.js" type="text/javascript" charset="utf-8"></script>

 

2、初始化jquery插件,以下是最简单的配置的js代码

 

代码如下:


$(document).ready(function(){
    $("a[rel^='prettyphoto']").prettyphoto();
});

 

下面是每种类型的html代码

1、单张图片

 

代码如下:


<a href="images/fullscreen/2.jpg" rel="prettyphoto" title="this is the description">
<img src="images/thumbnails/t_2.jpg" width="60" height="60" alt="this is the title" />
</a>

 

2、图片相册

 

代码如下:


<a href="images/fullscreen/1.jpg" rel="prettyphoto[pp_gal]" title="you can add caption to pictures.">
<img src="images/thumbnails/t_1.jpg" width="60" height="60" alt="red round shape" />
</a>
<a href="images/fullscreen/2.jpg" rel="prettyphoto[pp_gal]">
<img src="images/thumbnails/t_2.jpg" width="60" height="60" alt="nice building" />
</a>
<a href="images/fullscreen/3.jpg" rel="prettyphoto[pp_gal]">
<img src="images/thumbnails/t_3.jpg" width="60" height="60" alt="fire!" />
</a>
<a href="images/fullscreen/4.jpg" rel="prettyphoto[pp_gal]">
<img src="images/thumbnails/t_4.jpg" width="60" height="60" alt="rock climbing" />
</a>
<a href="images/fullscreen/5.jpg" rel="prettyphoto[pp_gal]">
<img src="images/thumbnails/t_5.jpg" width="60" height="60" alt="fly kite, fly!" />
</a>

 

3、单个flash

 

代码如下:


<a href="https://www.adobe.com/products/flashplayer/include/marquee/design.swf?width=792&height=294"
rel="prettyphoto[flash]" title="flash 10 demo">
<img src="images/thumbnails/flash-logo.jpg" alt="flash 10 demo" width="60" />
</a>

 

4、youtube视频

 

代码如下:


<a href="https://www.youtube.com/watch?v=qqxi8wmq_wm" rel="prettyphoto" title="">
<img src="images/thumbnails/flash-logo.jpg" alt="youtube" width="60" />
</a>

 

5、vimeo

 

代码如下:


<a href="https://vimeo.com/8245346" rel="prettyphoto" title=""> <img src="images/thumbnails/flash-logo.jpg" alt="youtube" width="60" /> </a>

 

6、quicktime影片

 

代码如下:


<a title="despicable me" rel="prettyphoto[movies]" href="https://trailers.apple.com/movies/universal/despicableme/despicableme-tlr1_r640s.mov?width=640&height=360"> <img src="/wp-content/themes/nmfe/images/thumbnails/quicktime-logo.png" alt="despicable me" width="50" /> </a> <a title="tales from earthsea" rel="prettyphoto[movies]" href="https://trailers.apple.com/movies/disney/talesfromearthsea/talesfromearthsea-tlr1_r640s.mov?width=640&height=340"> <img src="/wp-content/themes/nmfe/images/thumbnails/quicktime-logo.png" alt="tales from earthsea" width="50" /> </a> <a title="grease sing-a-long" rel="prettyphoto[movies]" href="https://trailers.apple.com/movies/paramount/greasesingalong/greasesingalong-tlr1_r640s.mov?width=640&height=272"> <img src="/wp-content/themes/nmfe/images/thumbnails/quicktime-logo.png" alt="grease sing-a-long" width="50" /> </a>

 

7、外部网站(iframe

 

代码如下:


<a href="https://www.google.com?iframe=true&width=100%&height=100%"
rel="prettyphoto[iframes]" title="google.com opened at 100%">google.com</a>
<a href="https://www.apple.com?iframe=true&width=500&height=250" rel="prettyphoto[iframes]">apple.com</a>
<a href="https://www.twitter.com?iframe=true&width=400&height=200" rel="prettyphoto[iframes]">twitter.com</a>

 

8、普通文本

 

代码如下:


<a href="#inline-1" rel="prettyphoto" ><img src="/wp-content/themes/nmfe/images/thumbnails/earth-logo.jpg" alt="" width="50" /></a>
<p id="inline-1" class="hide">
    <p>这里是普通的文本</p>
    <p>今天给大家介绍的prettyphoto希望大家能喜欢,这个是播放普通文本的html</p>
</p>

 

9、ajax内容

 

代码如下:


<a rel="prettyphoto[ajax]" href="/demos/prettyphoto-jquery-lightbox-clone/xhr_response.html?
ajax=true&width=325&height=185">ajax content</a>

 

三、总结

prettybox图片播放插件很好用,赶紧用它来打造你的专属相册吧!