jQuery图片特效脚本prettyPhoto简介

Web前端519.5K阅读模式

prettyPhoto是一款基于jquery的轻量级的lightbox图片特效脚本,它不仅支持图片,还同时支持视频、flash、 YouTube、iframe和ajax。而且prettyPhoto配置和使用都十分简单,扩展性也不错,你可以最大限度地自定义 prettyPhoto。prettyPhoto兼容大部分主流的浏览器,有些Wordpress图片插件就是基于此脚本制作的。

比如:Wordpress插件:Royal PrettyPhoto

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

http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

一、prettyPhoto使用方法介绍

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

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

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

  1. $(document).ready(function(){   
  2.     $("a[rel^='prettyPhoto']").prettyPhoto();   
  3. });  

下面是每种类型的html代码

1、单张图片

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

2、图片相册

  1. <a href="images/fullscreen/1.jpg" rel="prettyPhoto[pp_gal]" title="You can add caption to pictures.">   
  2. <img src="images/thumbnails/t_1.jpg" width="60" height="60" alt="Red round shape" />   
  3. </a>   
  4. <a href="images/fullscreen/2.jpg" rel="prettyPhoto[pp_gal]">   
  5. <img src="images/thumbnails/t_2.jpg" width="60" height="60" alt="Nice building" />   
  6. </a>   
  7. <a href="images/fullscreen/3.jpg" rel="prettyPhoto[pp_gal]">   
  8. <img src="images/thumbnails/t_3.jpg" width="60" height="60" alt="Fire!" />   
  9. </a>   
  10. <a href="images/fullscreen/4.jpg" rel="prettyPhoto[pp_gal]">   
  11. <img src="images/thumbnails/t_4.jpg" width="60" height="60" alt="Rock climbing" />   
  12. </a>   
  13. <a href="images/fullscreen/5.jpg" rel="prettyPhoto[pp_gal]">   
  14. <img src="images/thumbnails/t_5.jpg" width="60" height="60" alt="Fly kite, fly!" />   
  15. </a>  

3、单个flash

  1. <a href="http://www.adobe.com/products/flashplayer/include/marquee/design.swf?width=792&amp;height=294"  
  2. rel="prettyPhoto[flash]" title="Flash 10 demo">   
  3. <img src="images/thumbnails/flash-logo.jpg" alt="Flash 10 demo" width="60" />   
  4. </a>  

4、YouTube视频

  1. <a href="http://www.youtube.com/watch?v=qqXi8WmQ_WM" rel="prettyPhoto" title="">   
  2. <img src="images/thumbnails/flash-logo.jpg" alt="YouTube" width="60" />   
  3. </a>  

5、Vimeo

  1. <a href="http://vimeo.com/8245346" rel="prettyPhoto" title="">   
  2. <img src="images/thumbnails/flash-logo.jpg" alt="YouTube" width="60" />   
  3. </a>  

6、QuickTime影片

  1. <a title="Despicable Me" rel="prettyPhoto[movies]"  
  2. href="http://trailers.apple.com/movies/universal/despicableme/despicableme-tlr1_r640s.mov?width=640&height=360">   
  3. <img src="/wp-content/themes/NMFE/images/thumbnails/quicktime-logo.png" alt="Despicable Me" width="50" />   
  4. </a>   
  5. <a title="Tales from Earthsea" rel="prettyPhoto[movies]"  
  6. href="http://trailers.apple.com/movies/disney/talesfromearthsea/talesfromearthsea-tlr1_r640s.mov?width=640&height=340">   
  7. <img src="/wp-content/themes/NMFE/images/thumbnails/quicktime-logo.png" alt="Tales from Earthsea" width="50" />   
  8. </a>   
  9. <a title="Grease Sing-A-Long" rel="prettyPhoto[movies]"  
  10. href="http://trailers.apple.com/movies/paramount/greasesingalong/greasesingalong-tlr1_r640s.mov?width=640&height=272">   
  11. <img src="/wp-content/themes/NMFE/images/thumbnails/quicktime-logo.png" alt="Grease Sing-A-Long" width="50" />   
  12. </a>  

7、外部网站(iframe)

  1. <a href="http://www.google.com?iframe=true&width=100%&height=100%"  
  2. rel="prettyPhoto[iframes]" title="Google.com opened at 100%">Google.com</a>   
  3. <a href="http://www.apple.com?iframe=true&width=500&height=250" rel="prettyPhoto[iframes]">Apple.com</a>   
  4. <a href="http://www.twitter.com?iframe=true&width=400&height=200" rel="prettyPhoto[iframes]">Twitter.com</a>  

8、普通文本

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

9、AJAX内容

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

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
评论  5  访客  5
    • 华图官网
      华图官网 1

      博主在找点效果图就好了

      • BE
        BE 0

        我想知道这款插件安装后不是自动能给图片加特效啊? 还需要手动对每张图片设置? 有点太不人性化了,那样还不如直接用代码? 我以前用shadowbox,结果最近可能wordpress升级了,不能用了

        • wffger
          wffger 0

          不行哦,即使按照教程写了,还是不能在页面内弹窗显示新的页面

            • zhiyan
              zhiyan 0

              @ wffger 用auto-highslide吧,自动的,效果差不多

            • 小娆凸现
              小娆凸现 1

              make一下;不知道 目前最新的版本wordpress 4.0是否能用呢

            匿名

            发表评论

            匿名网友
            :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

            拖动滑块以完成验证