zoukankan      html  css  js  c++  java
  • 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="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 
    }); 
     
    属性说明:
     
    属性名默认值简要说明
    padding 10 浏览框内边距,和css中的padding一个意思
    margin 20 浏览框外边距,和css中的margin一个意思
    opacity false 如果为true,则fancybox在动画改变的时候透明度可以跟着改变
    modal false 如果为true,则'overlayShow' 会被设成 'true' , 'hideOnOverlayClick', 'hideOnContentClick', 'enableEscapeButton', 'showCloseButton' 会被设成 'false'
    cyclic false 如果为true,相册会循环播放
    scrolling 'auto' 设置overflow的值来创建或隐藏滚动条,可以设置成 'auto', 'yes', or 'no'
    width 560 设置iframe和swf的宽度,如果 'autoDimensions'为 'false',这也可以设置普通文本的宽度
    height 340 设置iframe和swf的高度,如果 'autoDimensions'为 'false',这也可以设置普通文本的高度
    autoScale true 如果为true,fancybox可以自适应浏览器窗口大小
    autoDimensions true 在内联文本和ajax中,设置是否动态调整元素的尺寸,如果为true,请确保你已经为元素设置了尺寸大小
    centerOnScroll false 如果为true,当你滚动滚动条时,fancybox将会一直停留在浏览器中心
    ajax { } 和jquery的ajax调用选项一样 注意: 'error' and 'success' 这两个回调事件会被fancybox重写
    swf {wmode: 'transparent'} swf的设置选项
    hideOnOverlayClick true 如果为true则点击遮罩层关闭fancybox
    hideOnContentClick false 如果为true则点击播放内容关闭fancybox
    overlayShow true 如果为true,则显示遮罩层
    overlayOpacity 0.3 遮罩层的透明度(范围0-1)
    overlayColor '#666' 遮罩层的背景颜色
    titleShow true 如果为true,则显示标题
    titlePosition 'outside' 设置标题显示的位置.可以设置成 'outside', 'inside' 或 'over'
    titleFormat null 可以自定义标题的格式
    transitionIn, transitionOut 'fade' 设置动画效果. 可以设置为 'elastic', 'fade' 或 'none'
    speedIn, speedOut 300 fade 和 elastic 动画切换的时间间隔, 以毫秒为单位
    changeSpeed 300 切换时fancybox尺寸的变化时间间隔(即变化的速度),以毫秒为单位
    changeFade 'fast' 切换时内容淡入淡出的时间间隔(即变化的速度)
    easingIn, easingOut 'swing' 为 elastic 动画使用 Easing
    showCloseButton true 如果为true,则显示关闭按钮
    showNavArrows true 如果为true,则显示上一张下一张导航箭头
    enableEscapeButton true 如果为true,则启用ESC来关闭fancybox
    onStart null 回调函数,加载内容是触发
    onCancel null 回调函数,取消加载内容后触发
    onComplete null 回调函数,加载内容完成后触发
    onCleanup null 回调函数,关闭fancybox前触发
    onClosed null 回调函数,关闭fancybox后触发
     

     方法说明:

    $.fancybox.showActivity 显示加载动画  
    $.fancybox.hideActivity 隐藏加载动画
    $.fancybox.close 关闭窗口  
    $.fancybox.resize 自动调整窗口的高度使之与内容相适应  
    Centered 是否将选区居中,即显示在容器的中心。 
    $.fancybox.next Displays the next gallery item
    $.fancybox.prev Displays the previous gallery item
    $.fancybox.pos Displays item by index from gallery
    $.fancybox.cancel Cancels loading content
    $.fancybox.close Hides FancyBox  Within an iframe use - parent.$.fancybox.close();
    $.fancybox.resize Auto-resizes FancyBox height to match height of content
    $.fancybox.center Centers FancyBox in viewport
  • 相关阅读:
    Omi新成员omi-router正式发布
    Omi架构与React Fiber
    Omi框架Store体系的前世今生
    Omi v1.0震撼发布
    omi-cli新版发布-升级webpack2和支持sass生成组件局部CSS
    Omi应用md2site-0.5.0发布-支持动态markdown拉取解析
    Omi应用md2site发布-markdown转网站利器
    AlloyTouch之无限循环select插件
    Omi教程-插件体系
    AlloyTouch之select选择插件
  • 原文地址:https://www.cnblogs.com/mistor/p/3099848.html
Copyright © 2011-2022 走看看