国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jquery自定義顯示消息數(shù)量

2024-05-06 15:23:28
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了jquery自定義顯示消息數(shù)量展示的具體代碼,供大家參考,具體內(nèi)容如下

根據(jù)需求簡單的實(shí)現(xiàn)一個(gè)小功能控件,暫時(shí)不支持?jǐn)U展。

$("xxxxxxx").iconCountPlugin(options, start, isOffset) {//三個(gè)參數(shù),自定義樣式,是否禁止圖標(biāo)位置隨瀏覽器窗口變化而變化,是否禁用偏移量這個(gè)是調(diào)用,后面?zhèn)z參數(shù)可以根據(jù)需求自行進(jìn)行調(diào)整,以兼容不同的瀏覽器,可能因?yàn)闉g覽器之間的差異導(dǎo)致出一些意想不到的錯(cuò)誤.復(fù)制代碼;(function ($, window, document, undefined) {var inforCountShow = function (target, option, isOffset) {this.$element = target;var str = "<span class = 'infor-count'></span>";var offsetleft = $(this.$element).offset().left;var offsetTop = $(this.$element).offset().top;var targetWidth = $(this.$element).width();var targetHeight = $(this.$element).height();var left = "",top = "";if (!isOffset) {left = offsetleft + targetWidth - 18;top = offsetTop - 5;} else {left = targetWidth + 13;top = targetHeight - 3;}$(this.$element).after(str);this.defaults = {'display': 'inline-block','width': '18px','height': '18px','position': 'absolute','backgroundColor': '#f43530','color': '#fff','borderRadius': '15px','textAlign': 'center','fontSize': '12px',"left": left,"top": top,"cursor": 'auto','margin':'auto'};this.options = $.extend({}, this.defaults, option);this.createdDom = $(str);}inforCountShow.prototype = {//手動(dòng)設(shè)置changeStyle: function () {return $(this.$element).next().css({'display': this.options.display,'width': this.options.width,'height': this.options.height,'position': this.options.position,'backgroundColor': this.options.backgroundColor,'color': this.options.color,'borderRadius': this.options.borderRadius,'zIndex': this.options.zIndex,'textAlign': this.options.textAlign,'fontSize': this.options.fontSize,"left": this.options.left,"top": this.options.top,'lineHeight': this.options.lineHeight,"cursor": this.options.cursor,"margin": this.options.margin});},//瀏覽器窗口大小改變自適應(yīng),默認(rèn)生效onResize: function (target, isOffset) {$(window).resize(function () {var newOffsetleft = $(target).offset().left;var newOffsetTop = $(target).offset().top;var newTargetWidth = $(target).width();var newTargetHeight = $(target).height();var newleft = "", newTop = "";if (!isOffset) {newleft = newOffsetleft + newTargetWidth - 18;newTop = newOffsetTop - 5;} else {newleft = newTargetWidth + 13;newTop = newTargetHeight - 3;}$(target).next().css({"left": newleft,"top": newTop});});},//數(shù)值溢出,當(dāng)消息數(shù)量超過99時(shí)顯示 "..."valueOverflow:function() {var value = $(this.$element).next().text();if (null != value && value>99) {$(this.$element).next().text("...");}},//綁定事件,可以接受事件對(duì)應(yīng)外部方法bindEvent: function () {var that = this;if (!that.createdDom) return;this.createdDom.off('click').on('click', function () {if (that.options.click) {// that.options.click();} else {}});}}//調(diào)用$.fn.iconCountPlugin = function (options, start, isOffset) {//三個(gè)參數(shù),自定義樣式,是否禁止圖標(biāo)位置隨瀏覽器窗口變化而變化,是否禁用偏移量return $(this).each(function () {var infor = new inforCountShow(this, options, isOffset);if (!start) {infor.onResize(this, isOffset);}infor.changeStyle();infor.valueOverflow();infor.bindEvent();});}})(jQuery, window, document);            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 册亨县| 旺苍县| 汉沽区| 阿坝| 保靖县| 临潭县| 平顶山市| 海原县| 泸水县| 余干县| 巢湖市| 禄劝| 诏安县| 昭苏县| 洛扎县| 佛山市| 嘉荫县| 汕头市| 石棉县| 毕节市| 兴山县| 乌兰县| 和顺县| 沁阳市| 铁力市| 上饶市| 杂多县| 徐闻县| 军事| 绿春县| 福安市| 唐河县| 周至县| 永福县| 顺平县| 鄯善县| 衡南县| 泸西县| 府谷县| 滕州市| 济南市|