本文实例为大家分享了jquery自定义显示消息数量展示的具体代码,供大家参考,具体内容如下
根据需求简单的实现一个小功能控件,暂时不支持扩展。
$("xxxxxxx").iconCountPlugin(options, start, isOffset) { //三个参数,自定义样式,是否禁止图标位置随浏览器窗口变化而变化,是否禁用偏移量 这个是调用,后面俩参数可以根据需求自行进行调整,以兼容不同的浏览器,可能因为浏览器之间的差异导致出一些意想不到的错误. 复制代码 ; (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 = { //手动设置 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 }); }, //浏览器窗口大小改变自适应,默认生效 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 }); }); }, //数值溢出,当消息数量超过99时显示 "..." valueOverflow:function() { var value = $(this.$element).next().text(); if (null != value && value>99) { $(this.$element).next().text("..."); } }, //绑定事件,可以接受事件对应外部方法 bindEvent: function () { var that = this; if (!that.createdDom) return; this.createdDom.off('click').on('click', function () { if (that.options.click) { // that.options.click(); } else { } }); } } //调用 $.fn.iconCountPlugin = function (options, start, isOffset) { //三个参数,自定义样式,是否禁止图标位置随浏览器窗口变化而变化,是否禁用偏移量 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);
此插件是笔者当时刚学习封装控件时的初次尝试,希望大佬们勿喷,有时间会把他进行优化,欢迎各位大神一起讨论.您的点赞是我最好的动力。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年09月24日
2024年09月24日
- 时代少年团《「叁重楼」演唱会 -「楼间楼」重庆站LIVE》[FLAC/分轨][820.86MB]
- 许廷铿2017《THEULTIMATECOLLECTION》2CD[星梦娱乐][WAV+CUE]
- 许佳慧-独家情话[WAV+CUE]
- 张惠妹《ThePowerOfA-Mei》2018[SACD/ISO]
- 陈珊妮.2013-低调人生2CD【和气音乐】【WAV+CUE】
- 群星.2000-超级BAND.BAND.BAND【滚石】【WAV+CUE】
- 许志安.2002-On.Show演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 蔡琴-哈利路亚2016[SACD/ISO]
- 陈随意2011-今生只为你[豪记][WAV+CUE]
- 陈随意2008-爱的总铺师[美华][WAV+CUE]
- 裘德《一棵树所创造的》[320K/MP3][56.21MB]
- 裘德《一棵树所创造的》[24bit 48kHz][FLAC/分轨][355.1MB]
- 卓依娜姆《美人谋 网剧影视原声带》[320K/MP3][48.29MB]
- 张星特.2024-流绪呢喃【中视鸣达】【FLAC分轨】
- 邓紫棋.2010-MYSECRET【蜂鸟音乐】【WAV+CUE】