FancyBox的使用技巧 (汇总)

js:
$(document).ready(function() {
$("#various1").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none'
});
});
html:
<li><a id="various1" href="#inline1" title="Lorem ipsum dolor sit amet">Inline</a></li>
 
<div style="display: none;"> //隐藏的元素必须在display:none里面
<div id="inline1" style="width:400px;height:100px;overflow:auto;">内容</div>
</div>
 
 
1,弹出框如何实现圆角?
要实现fancybox的圆角还需要另一个js插件,就是corner,可以到http://jquery.malsup.com/corner/ 下载,  
<script type="text/javascript" src="http://malsup.github.com/jquery.corner.js"></script>
导入两个插件后用下面的代码即可以实现圆角。
$('a.iframe').fancybox({
  'overlayShow' : true,
  'showCloseButton':
  'overlayColor' : "#000000", //要指定黑色背景,
  'overlayOpacity' : 0.8, //
  'onComplete' :
    $('#fancybox-outer, #fancybox-content').corner('10px'); //利用corner实现圆角
  }
});
 
2,如何关闭弹出的iframe
使用这个js即可 parent.$.fancybox.close();  
需要注意的是,必须通过服务器请求才行,本地文件打开的方式关不掉。
 
3,如何不使用默认的关闭,自定义关闭
如何关闭弹出的层? $.fancybox.close();  通用
 
4,如何在关闭弹出框的同时刷新页面  返回消息等回调事件
$('a.iframe').fancybox({ 
//其它参数 
   'onClosed' : function() { window.location.href = 'index.aspx';},
      'onStart':function() {return window.confirm('Continue?');},
      'onCancel':function() {alert('Canceled!');},
      'onComplete':function() {  alert('Completed!');},
      'onCleanup':function() {return window.confirm('Close?');}
});
 
5,弹窗播放优酷等视频
导入fancybox的js css后 
 
html: 
<a class="video" href="your_swf_url" > 
<img src="img_url" /> 
</a> 
 
js: 
$('.video')j.fancybox({ 
'padding' : 0, 
'autoScale' : false, 
'transitionIn' : 'none', 
'transitionOut' : 'none', 
'overlayOpacity' : options.overlayOpacity, 
'hideOnOverlayClick': false 
}); 
 
属性说明:
 
属性名默认值简要说明
padding10浏览框内边距,和css中的padding一个意思
margin20浏览框外边距,和css中的margin一个意思
opacityfalse如果为true,则fancybox在动画改变的时候透明度可以跟着改变
modalfalse如果为true,则'overlayShow' 会被设成 'true' , 'hideOnOverlayClick', 'hideOnContentClick', 'enableEscapeButton', 'showCloseButton' 会被设成 'false'
cyclicfalse如果为true,相册会循环播放
scrolling'auto'设置overflow的值来创建或隐藏滚动条,可以设置成 'auto', 'yes', or 'no'
width560设置iframe和swf的宽度,如果 'autoDimensions'为 'false',这也可以设置普通文本的宽度
height340设置iframe和swf的高度,如果 'autoDimensions'为 'false',这也可以设置普通文本的高度
autoScaletrue如果为true,fancybox可以自适应浏览器窗口大小
autoDimensionstrue在内联文本和ajax中,设置是否动态调整元素的尺寸,如果为true,请确保你已经为元素设置了尺寸大小
centerOnScrollfalse如果为true,当你滚动滚动条时,fancybox将会一直停留在浏览器中心
ajax{ }和jquery的ajax调用选项一样 注意: 'error' and '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后触发
 

 方法说明:

$.fancybox.showActivity 显示加载动画  
$.fancybox.hideActivity 隐藏加载动画
$.fancybox.close 关闭窗口  
$.fancybox.resize 自动调整窗口的高度使之与内容相适应  
Centered 是否将选区居中,即显示在容器的中心。 
$.fancybox.nextDisplays the next gallery item
$.fancybox.prevDisplays the previous gallery item
$.fancybox.posDisplays item by index from gallery
$.fancybox.cancelCancels loading content
$.fancybox.closeHides FancyBox  Within an iframe use - parent.$.fancybox.close();
$.fancybox.resizeAuto-resizes FancyBox height to match height of content
$.fancybox.centerCenters FancyBox in viewport
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值