图片预览插件 fancyBox

今天给大家分享一款优秀的 jquery 弹出层展示插件 fancybox。它除了能够展示图片之外,还可以展示 flash、iframe 内容、html 文本以及 ajax 调用,我们可以通过 css 来自定义外观


原文与源码来自:http://tqcto.com/article/web/53337.html


中文文档网址:点击打开链接


Demo下载地址:点击打开链接

效果图



fancybox 特点:

  1. 可以支持图片、html 文本、flash 动画、iframe 以及 ajax 的支持;
  2. 可以自定义播放器的 css 样式;
  3. 可以以组的形式进行播放;
  4. 如果将鼠标滚动插件(mouse wheel plugin)包含进来的话 fancybox 还能支持鼠标滚轮滚动来翻阅图片;
  5. fancybox 播放器支持投影,更有立体的感觉。

fancybox 使用方法:

首先需要引入 jquery 核心库和 fancybox 插件:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

如果需要用 transition(一些动画效果)你还需要引入以下 js:

<script src="/fancybox/jquery.easing-1.4.pack.js"></script>

如果需要支持鼠标滚轮滚动效果你还需要引入以下 js:

<script src="/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>

然后引入样式表:

<link rel="stylesheet" href="/fancybox/jquery.fancybox-1.3.4.css"/>

之后在页面上添加一个 a 标签:

<a id="single_image" href="image_big.jpg"><img src="image_small.jpg" alt=""/></a>

其中 a 标签的 href 中的图片就是我们需要弹层显示的大图。

最后调用 fancybox 方法:

$("#single_image").fancybox();

当然这只能显示一张图片,有时候我们可能需要做个相册之类的多张图片,那么可以用 rel 属性来创建图片组(也就是 fancybox 特点的第三点),如下代码:

<a class="grouped_elements" rel="group1" href="image_big_1.jpg"><img src="image_small_1.jpg" alt=""/></a>
<a class="grouped_elements" rel="group1" href="image_big_2.jpg"><img src="image_small_2.jpg" alt=""/></a>

调用方法也很简单:

$(".grouped_elements").fancybox();

fancybox 参数:

fancybox 之所以优秀是因为它的参数配置很强大,几乎可以满足我们所有的需要。

属性值默认值描述
padding10播放器内边距的值
margin20播放器外边距的值
opacityfalse如果为 true,则 fancybox 在动画改变的时候透明度可以跟着改变
modalfalse如果为 true,则 'overlayShow' 会被设成 'true','hideOnOverlayClick','hideOnContentClick','enableEscapeButton','showCloseButton' 会被设成 'false'
cyclicfalse如果为 true,相册会循环播放
scrolling'auto'设置 overflow 的值来创建或隐藏滚动条,可以设置成 'auto','yes' 或 'no'
width560设置 iframe 和 swf 的宽度,如果 'autoDimensions' 为 'false',这也可以设置普通文本的宽度
height340设置 iframe 和 swf 的高度,如果 'autoDimensions' 为 'false',这也可以设置普通文本的高度
autoScaletrue如果为 true,fancybox 可以自适应浏览器窗口大小
autoDimensionstrue在内联文本和 ajax 中,设置是否动态调整元素的尺寸,如果为 true,请确保你已经为元素设置了尺寸大小
centerOnScrollfalse如果为 true,当你滚动滚动条时,fancybox将会一直停留在浏览器中心
ajax{ }和 jquery 的 ajax 调用选项一样。注意:'error' 和 'success' 这两个回调事件会被 fancybox 重写
swf{wmode: 'transparent'}swf 的设置选项
hideOnOverlayClicktrue如果为 true,则点击遮罩层关闭 fancybox
hideOnContentClickfalse如果为 true,则点击播放内容关闭 fancybox
overlayShowtrue如果为 true,则显示遮罩层
overlayOpacity0.3遮罩层的透明度(范围0-1)
overlayColor'#666'遮罩层的背景颜色
titleShowtrue如果为 true,则显示标题
titlePosition'outside'设置标题显示的位置,可以设置成 'outside','inside' 或 'over'
titleFormatnull可以自定义标题的格式
transitionIn,transitionOut'fade'设置动画效果,可以设置为 'elastic','fade' 或 'none'
speedIn,speedOut300fade 和 elastic 动画切换的时间间隔,以毫秒为单位
changeSpeed300切换时 fancybox 尺寸的变化时间间隔(即变化的速度),以毫秒为单位
changeFade'fast'切换时内容淡入淡出的时间间隔(即变化的速度)
easingIn,easingOut'swing'为 elastic 动画使用 Easing
showCloseButtontrue如果为 true,则显示关闭按钮
showNavArrowstrue如果为 true,则显示上一张下一张导航箭头
enableEscapeButtontrue如果为 true,则启用 esc 来关闭 fancybox
onStartnull回调函数,加载内容时触发
onCancelnull回调函数,取消加载内容后触发
onCompletenull回调函数,加载内容完成后触发
onCleanupnull回调函数,关闭 fancybox 前触发
onClosednull回调函数,关闭 fancybox 后触发









































原文与源码来自:http://tqcto.com/article/web/53337.html


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
How to use 1. Setup Include nessesary JS files (FancyBox uses pngFix to fix IE png transparency). --------------------------- /* required */ <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.fancybox.js"></script> /* optional */ <script type="text/javascript" src="js/jquery.pngFix.js"></script> <script type="text/javascript" src="js/jquery.metadata.js"></script> -------------------------------------------- Include FancyBox CSS file. Dont forget to change image paths. -------------------------------------------- <link rel="stylesheet" href="css/fancybox.css" type="text/css" media="screen"> -------------------------------------------- 2. Add your images Add images and wrap them with a link to the zoomed version -------------------------------------------- <a href="image_big.jpg"><img src="image_small.jpg" alt=""/></a> -------------------------------------------- Optional: Use the title attribute if you want to show a caption Optional: Use the rel attribute to group images 3. Use the plugin Sample examples: -------------------------------------------- $(document).ready(function() { $("p#test1 a").fancybox(); $("p#test2 a").fancybox({ 'hideOnContentClick': true }); $("p#test3 a").fancybox({ 'zoomSpeedIn': 0, 'zoomSpeedOut': 0, 'overlayShow': true }); }); ------------------------------------------- Available options hideOnContentClick Hides FancyBox when cliked on zoomed item (false by default) zoomSpeedIn Speed in miliseconds of the zooming-in animation (no animation if 0) zoomSpeedOut Speed in miliseconds of the zooming-out animation (no animation if 0) frameWidth Default width for iframed and inline content frameHeight Default height for iframed and inline content overlayShow If true, shows the overlay (false by default) overlayOpacity Opacity of overlay (from 0 to 1) itemLoadCallback Custom function to get group items (see example on this page source) Comments
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值