最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

屬于你的jQuery提示框(Tip)插件

 更新時間:2016年01月20日 14:39:29   作者:雕哥  
這篇文章主要分享了一款屬于你的jQuery提示框(Tip)插件,功能很強大,希望大家喜歡

插件可以滿足常用的提示顯示,支持12個方向,支持邊框、背景色、文本顏色自定義,支持位置微調(diào)、層級微調(diào)、寬度間距等參數(shù)調(diào)整。

先看看效果:

tips:提示信息組件
參數(shù):

  • msg:'asdf',內(nèi)容
  • dire:2,方向
  • w:250,寬度
  • _x:0,橫向偏移
  • _y:0,縱向偏移
  • zIndex:100000,層級
  • borderColor:#FFF,邊框顏色
  • bgColor:#FFF,背景顏色
  • useHover:true是否使用懸浮顯示
  • color:默認(rèn)提示文字顏色
  • padding:邊距

javascript代碼:

(function ($) {
  var defaults = {
    dire: 12,
    w: 250,
    _x: 0,
    _y: 0,
    borderColor: '#FFBB76',
    bgColor: '#FFFCEF',
    color: '#FF0000',
    padding: [5, 10],
    arrWidth: 10,
    useHover: true,
    zIndex: 100000
  };
  $.fn.tips = function (opt) {
    var tip, opts = $.extend({}, defaults, opt);
    if (this[0]) {
      opts.tag = this;
      if (opts.useHover) {
        opts.tag.hover(function () {
          tip = new Tip(opts);
          tip.show();
        }, function () {
          tip.close();
        });
      } else {
        tip = new Tip(opts);
        tip.show();
      }
      return this;
    }
  };
  function Tip(opts) {
    this.dire = opts.dire;
    this.width = opts.w;
    this.zIndex = opts.zIndex;
    this.borderColor = opts.borderColor;
    this.bgColor = opts.bgColor;
    this.color = opts.color;
    this.padding = opts.padding;
    this.arrWidth = opts.arrWidth;
    this.offsetX = opts._x;
    this.offsetY = opts._y;
    this.tag = opts.tag;
    this.msg = opts.msg;
    this.wrap = $('<div class="tip-wrap"></div>');
    this.innerArr = $('<div class="tip-arr-a"></div>');
    this.outerArr = $('<div class="tip-arr-b"></div>');
    this.init();
  };
  Tip.prototype = {
    init: function () {
      var msg = this.tag.data('tipMsg');
      if (!this.msg) {
        this.msg = msg;
      }
      this.createTemp();
    },
    createTemp: function () {
      var t = this;
      t.createWrap();
      t.setPosition();
    },
    createWrap: function () {
      var t = this;
      t.wrap.html(t.msg);
      var wrapCSS = {
        width: t.width,
        border: '1px solid ' + t.borderColor,
        'border-radius': '5px',
        background: t.bgColor,
        color: t.color,
        padding: t.getPadding()
      };
      t.outerArr.css(t.getArrStyle(t.dire, t.arrWidth, t.borderColor));
      t.innerArr.css(t.getArrStyle(t.dire, t.arrWidth, t.bgColor));
      t.wrap.prepend(t.innerArr).prepend(t.outerArr).css(wrapCSS);
      $('body').append(t.wrap);
    },
    setPosition: function () {
      var t = this;
      var posObj = t.getPos(t.dire, t.getPosition(t.tag), t.getPosition(t.wrap), t.arrWidth), pos = posObj.pos, innerPos = posObj.innerPos, outerPos = posObj.outerPos;
      t.wrap.css({top: pos.y, left: pos.x});
      t.innerArr.css({top: innerPos.y, left: innerPos.x});
      t.outerArr.css({top: outerPos.y, left: outerPos.x});
    },
    getPadding: function () {
      var t = this, pad = '0px', padArr = t.padding, len = padArr.length;
      switch (len) {
        case 1:
          pad = padArr[0] + 'px';
          break;
        case 2:
          pad = padArr[0] + 'px ' + padArr[1] + 'px';
          break;
        case 3:
          pad = padArr[0] + 'px ' + padArr[1] + 'px ' + padArr[2] + 'px';
          break;
        case 4:
          pad = padArr[0] + 'px ' + padArr[1] + 'px ' + padArr[2] + 'px ' + padArr[3] + 'px';
          break;
      }
      return pad;
    },
    getPosition: function (tag) {
      return {t: tag.offset().top, l: tag.offset().left, h: tag.outerHeight(), w: tag.outerWidth()};
    },
    getArrStyle: function (dir, width, color) {
      var style;
      switch (dir) {
        case 11:
        case 12:
        case 1:
          style = {
            'border-bottom-style': 'solid',
            'border-width': '0px ' + width + 'px ' + width + 'px',
            'border-bottom-color': color
          };
          break;
        case 2:
        case 3:
        case 4:
          style = {
            'border-left-style': 'solid',
            'border-width': width + 'px 0px ' + width + 'px ' + width + 'px',
            'border-left-color': color
          };
          break;
        case 5:
        case 6:
        case 7:
          style = {
            'border-top-style': 'solid',
            'border-width': width + 'px ' + width + 'px 0px',
            'border-top-color': color
          };
          break;
        case 8:
        case 9:
        case 10:
          style = {
            'border-right-style': 'solid',
            'border-width': width + 'px ' + width + 'px ' + width + 'px 0px',
            'border-right-color': color
          };
          break;
      }
      return style || {};
    },
    getPos: function (d, tagPos, pos, arrWidth) {
      var _pos, _innerPos, _outerPos, l = tagPos.l, t = tagPos.t, w = tagPos.w, h = tagPos.h, ww = pos.w, hh = pos.h;
      switch (d) {
        case 0:
        case 1:
          _pos = {x: l + w / 2 + arrWidth + 20 + 1 - ww, y: t + h + arrWidth};
          _outerPos = {x: ww - 2 - 20 - arrWidth * 2, y: -arrWidth};
          _innerPos = {x: ww - 2 - 20 - arrWidth * 2, y: -arrWidth + 1};
          break;
        case 2:
          _pos = {x: l - ww - arrWidth, y: t + h / 2 - arrWidth - 20 - 1};
          _outerPos = {x: ww - 2, y: 20};
          _innerPos = {x: ww - 2 - 1, y: 20};
          break;
        case 3:
          _pos = {x: l - ww - arrWidth, y: t + h / 2 - hh / 2};
          _outerPos = {x: ww - 2, y: (hh - 2) / 2 - arrWidth};
          _innerPos = {x: ww - 2 - 1, y: (hh - 2) / 2 - arrWidth};
          break;
        case 4:
          _pos = {x: l - ww - arrWidth, y: t + h / 2 + arrWidth + 20 + 1 - hh};
          _outerPos = {x: ww - 2, y: hh - 2 - 20 - arrWidth * 2};
          _innerPos = {x: ww - 2 - 1, y: hh - 2 - 20 - arrWidth * 2};
          break;
        case 5:
          _pos = {x: l + w / 2 + arrWidth + 20 + 1 - ww, y: t - arrWidth - hh};
          _outerPos = {x: ww - 2 - 20 - arrWidth * 2, y: hh - 2};
          _innerPos = {x: ww - 2 - 20 - arrWidth * 2, y: hh - 2 - 1};
          break;
        case 6:
          _pos = {x: l + w / 2 - ww / 2, y: t - arrWidth - hh};
          _outerPos = {x: (ww - 2) / 2 - arrWidth, y: hh - 2};
          _innerPos = {x: (ww - 2) / 2 - arrWidth, y: hh - 2 - 1};
          break;
        case 7:
          _pos = {x: l + w / 2 - 20 - arrWidth, y: t - arrWidth - hh};
          _outerPos = {x: 20, y: hh - 2};
          _innerPos = {x: 20, y: hh - 2 - 1};
          break;
        case 8:
          _pos = {x: l + w + arrWidth, y: t + h / 2 + arrWidth + 20 + 1 - hh};
          _outerPos = {x: -arrWidth, y: hh - 2 - 20 - arrWidth * 2};
          _innerPos = {x: -arrWidth + 1, y: hh - 2 - 20 - arrWidth * 2};
          break;
        case 9:
          _pos = {x: l + w + arrWidth, y: t + h / 2 - hh / 2};
          _outerPos = {x: -arrWidth, y: (hh - 2) / 2 - arrWidth};
          _innerPos = {x: -arrWidth + 1, y: (hh - 2) / 2 - arrWidth};
          break;
        case 10:
          _pos = {x: l + w + arrWidth, y: t + h / 2 - arrWidth - 20 - 1};
          _outerPos = {x: -arrWidth, y: 20};
          _innerPos = {x: -arrWidth + 1, y: 20};
          break;
        case 11:
          _pos = {x: l + w / 2 - 20 - arrWidth, y: t + h + arrWidth};
          _outerPos = {x: 20, y: -arrWidth};
          _innerPos = {x: 20, y: -arrWidth + 1};
          break;
        case 12:
          _pos = {x: l + w / 2 - ww / 2, y: t + h + arrWidth};
          _outerPos = {x: (ww - 2) / 2 - arrWidth, y: -arrWidth};
          _innerPos = {x: (ww - 2) / 2 - arrWidth, y: -arrWidth + 1};
          break;
        default:
          _pos = {x: 0, y: 0};
      }
      return {
        pos: _pos,
        innerPos: _innerPos,
        outerPos: _outerPos
      };
    },
    show: function () {
      this.wrap.show();
    },
    close: function () {
      this.wrap.remove();
    }
  };
})(jQuery);

CSS:

.tip-wrap {
  position: absolute;
  display: none;
}

.tip-arr-a, .tip-arr-b {
  position: absolute;
  width: 0;
  height: 0;
  line-height: 0;
  border-style: dashed;
  border-color: transparent;
}
page:

<div class="test">
  <span data-tip-msg="我是測試數(shù)據(jù)<br>我是測試數(shù)據(jù)<br>我是測試數(shù)據(jù)">我是測試數(shù)據(jù)</span>
</div>

<script>
  $('.test span').tips();
</script>

效果:


以上就是一款簡簡單單的jQuery提示框(Tip)插件,希望大家可應(yīng)用到自己的項目中,有所收獲。

相關(guān)文章

  • 微信小程序中獲取設(shè)備信息的方法

    微信小程序中獲取設(shè)備信息的方法

    這篇文章主要給大家介紹了關(guān)于微信小程序中獲取設(shè)備信息的相關(guān)資料,微信小程序是一種在微信平臺上運行的應(yīng)用程序,它具有輕量化、便捷性和高兼容性的特點,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • js中一個函數(shù)獲取另一個函數(shù)返回值問題探討

    js中一個函數(shù)獲取另一個函數(shù)返回值問題探討

    在本文將為大家詳細(xì)探討下js中一個函數(shù)獲取另一個函數(shù)返回值問題,比較模糊的朋友可以學(xué)習(xí)下哦
    2013-11-11
  • 關(guān)于javascript中dataset的問題小結(jié)

    關(guān)于javascript中dataset的問題小結(jié)

    本文給大家介紹javascript中dataset的問題詳解,包括dataset的基礎(chǔ)用法,使用dataset的作用以及dataset的基礎(chǔ)操作等相關(guān)問題,對javascript dataset問題感興趣的朋友一起學(xué)習(xí)吧
    2015-11-11
  • JavaScript中判斷整數(shù)的多種方法總結(jié)

    JavaScript中判斷整數(shù)的多種方法總結(jié)

    這篇文章主要介紹了JavaScript中判斷整數(shù)的多種方法總結(jié),本文總結(jié)了5種判斷整數(shù)的方法,如取余運算符判斷、Math.round、Math.ceil、Math.floor判斷等,需要的朋友可以參考下
    2014-11-11
  • JavaScript中常見的Polyfill示例詳解

    JavaScript中常見的Polyfill示例詳解

    這篇文章主要介紹了JavaScript中常見Polyfill的相關(guān)資料,Polyfill是一種代碼,用于在舊版瀏覽器中實現(xiàn)不支持的現(xiàn)代JavaScript功能,以確??鐬g覽器兼容性和代碼統(tǒng)一性,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-04-04
  • JS識別瀏覽器類型(電腦瀏覽器和手機瀏覽器)

    JS識別瀏覽器類型(電腦瀏覽器和手機瀏覽器)

    本文給大家分享一段js代碼關(guān)于識別瀏覽器的類型是手機瀏覽器還是電腦瀏覽器,有需要的朋友可以參考下本文
    2016-11-11
  • 微信小程序分享小程序碼的生成(帶參數(shù))以及參數(shù)的獲取

    微信小程序分享小程序碼的生成(帶參數(shù))以及參數(shù)的獲取

    這篇文章主要介紹了微信小程序分享小程序碼的生成(帶參數(shù))以及參數(shù)的獲取,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • JavaScript中7種位運算符在實戰(zhàn)的妙用

    JavaScript中7種位運算符在實戰(zhàn)的妙用

    位運算是在數(shù)字底層(即表示數(shù)字的 32 個數(shù)位)進(jìn)行運算的,下面這篇文章主要給大家介紹了關(guān)于JavaScript中7種位運算符在實戰(zhàn)的妙用,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • 小程序?qū)崿F(xiàn)列表點贊功能

    小程序?qū)崿F(xiàn)列表點贊功能

    這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)列表點贊功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • JavaScript提取元素中第一個子元素的實現(xiàn)方法

    JavaScript提取元素中第一個子元素的實現(xiàn)方法

    本文主要介紹了JavaScript提取元素中第一個子元素的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06

最新評論

丹东市| 石城县| 绵竹市| 文昌市| 当雄县| 成武县| 山阴县| 上饶县| 玉溪市| 和政县| 宝清县| 江北区| 台安县| 阳东县| 沿河| 衡水市| 盐池县| 河南省| 衡山县| 临朐县| 晴隆县| 平和县| 团风县| 泰兴市| 札达县| 万山特区| 门源| 南开区| 磴口县| 焉耆| 福海县| 台东县| 临夏市| 东莞市| 静海县| 砀山县| 盐亭县| 大埔区| 武乡县| 嘉荫县| 封开县|