Chinaunix首页 | 论坛 | 博客
  • 博客访问: 365112
  • 博文数量: 284
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1707
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-14 16:38
文章分类

全部博文(284)

文章存档

2015年(6)

2014年(278)

我的朋友

分类: Html/Css

2014-09-17 17:22:47

1. [代码][JavaScript]代码     

//调用说明
//$(selector).bub($(selector) | string[, options]);
//示例: $('#demo1').bub('hello, world!');
//options 说明
//defaults: {
//    color: '#e6e6e6',               //背景颜色
//    padding: '10px',                //内边距
//    radius: '5px',                  //圆角半径(css3)
//    shadow: 'none',                 //阴影(css3)
//    left: 0,                        //位置x轴偏移
//    top: 0,                         //位置y轴偏移
//    arrow_size: '15px',             //气泡的箭头大小
//    arrow_direct: ['top', 'left'],  //气泡的箭头指向方位([0]:'top'|'bottom',[1]:'left'|'right')
//    click_blank_hide: true          //点击页面空白处时是否销毁气泡
//}
 
(function () {
  $.fn.extend({
    bub: function (content, opts) {
      var merge = function (all, segment) {
          var ret = {};
          for (var o in all) {
            ret[o] = segment[o] === undefined ? all[o] : segment[o];
          }
          return ret;
        };
      var defaults = {
        color: '#e6e6e6',
        padding: '10px',
        radius: '5px',
        shadow: 'none',
        left: 0,
        top: 0,
        arrow_size: '15px',
        arrow_direct: ['top', 'left'],
        click_blank_hide: true
      };
      opts = merge(defaults, opts || {});
      this.each(function () {
        if ($(this).data().buber) {
          $(this).un_bub();
        }
        var bub_box = $('
\
                    \
                    \
                    \
                    \
                    \
                    \
');
        $('body').append(bub_box);
        $(this).data().buber = bub_box;
        $(this).attr('ns_bub_binder', opts.click_blank_hide);
        if (content instanceof $) {
          content = content.clone();
          content.show();
        }
        bub_box.find('.ns_bub_wrapper').append(content);
      });
    },
    un_bub: function () {
      this.each(function () {
        var bub_box = $(this).data().buber;
        if (bub_box === undefined) return;
        delete $(this).data().buber;
        bub_box.remove();
      });
    }
  });
  $(function () {
    $(document).click(function (e) {
      e = e || window.event;
      var src = e.target || e.srcElement;
      if ($(src).attr('class') == 'ns_bub_box' || $(src).attr('class') == 'ns_bub_wrapper' || $(src).attr('ns_bub_binder') !== undefined) return;
      $('*[ns_bub_binder=true]').un_bub();
    });
  });
})(window);
阅读(441) | 评论(0) | 转发(0) |
0

上一篇:css3 点击爆炸下落

下一篇:CSS3分享功能

给主人留下些什么吧!~~