简单的移动端提示插件

javascript

function FEerNotice(opt){
  var opt = opt || {}
  this.opt = {
    text: opt.text || "加载中..",
    duration: opt.duration || 300,
    type: opt.type || ‘loading‘
  };

  //生成指定的dom
  this.createDom = function(){
    var loadingDom = document.createElement(‘div‘);
    loadingDom.id = ‘FEerloading‘;
    loadingDom.className = ‘FEerloading hide‘;

    var backDrop = document.createElement(‘div‘);
    backDrop.className = ‘backDrop‘;
    switch (this.opt.type){
      case ‘loading‘:
        var loadingIcon = document.createElement(‘i‘);
        loadingIcon.className = "FEer-loading-icon";
      break;
      case ‘success‘:
        var loadingIcon = document.createElement(‘i‘);
        loadingIcon.className = "FEer-success-icon";
      break;
      case ‘failed‘:
        var loadingIcon = document.createElement(‘i‘);
        loadingIcon.className = "FEer-failed-icon";
      break;
      default:
        var loadingIcon = document.createElement(‘i‘);
    }
    var txt = document.createTextNode(this.opt.text);

    backDrop.appendChild(loadingIcon);
    backDrop.appendChild(txt);
    loadingDom.appendChild(backDrop);

    return loadingDom;
  }

  //显示
  if(typeof this.show != ‘function‘){
    FEerNotice.prototype.show = function(){
      if(!document.getElementById(‘FEerloading‘)){
        var dom = this.createDom();
        document.getElementsByTagName(‘body‘)[0].appendChild(dom);

        document.getElementById("FEerloading").className = ‘FEerloading‘;
      }else{
        document.getElementById("FEerloading").className = ‘FEerloading‘;
      }
    }
  }
  //隐藏
  if(typeof this.hide != ‘function‘){
    FEerNotice.prototype.hide = function(){
      if(!!document.getElementById(‘FEerloading‘)){
        document.getElementById("FEerloading").className = ‘FEerloading hide‘;
      }
    }
  }
  //定时显示隐藏
  if(typeof this.autoHide != ‘function‘){
    FEerNotice.prototype.autoHide = function(){
      if(!document.getElementById(‘FEerloading‘)){
        var dom = this.createDom();
        document.getElementsByTagName(‘body‘)[0].appendChild(dom);

        document.getElementById("FEerloading").className = ‘FEerloading‘;
      }else{
        document.getElementById("FEerloading").className = ‘FEerloading‘;
      }

      setTimeout(function(){
        document.getElementById("FEerloading").className = ‘FEerloading hide‘;
      }.bind(this), this.opt.duration)
    }
  }
}

css

#FEerloading{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.7);
    z-index: 9999;
}
#FEerloading .backDrop{
    min-width: 100px;
    min-height: 100px;
    text-align: center;
    border-radius: 4px;
    color: rgba(255,255,255,.8);
    background: rgba(0,0,0,.8);
}
#FEerloading .backDrop i{
    position: relative;
    display: block;
    margin: 10px auto 10px;
    height: 50px;
    width: 50px;
    overflow: hidden;
}
#FEerloading .backDrop i.FEer-loading-icon{
    background: #d7ad6a;
    border-radius: 50%;
}
#FEerloading .backDrop i.FEer-loading-icon:before{
    content: "";
    position: absolute;
    top: -98px;
    left: 50%;
    margin-left: -60px;
    width: 120px;
    height: 120px;
    background: rgba(0,0,0,.5);
    border-radius: 50px;
    -webkit-animation: roll-before 7s linear infinite;
}
@-webkit-keyframes roll-before{
    from {transform: rotate(0deg);}
    to {transform: rotate(360deg);}
}
#FEerloading .backDrop i.FEer-loading-icon:after{
    content: "";
    position: absolute;
    top: -97px;
    left: 50%;
    margin-left: -60px;
    width: 120px;
    height: 120px;
    background: rgba(0,0,0,.5);
    border-radius: 45px;
    -webkit-animation: roll-after 5s linear infinite;
}
@-webkit-keyframes roll-after{
    from {transform: rotate(0deg);}
    to {transform: rotate(360deg);}
}
#FEerloading .backDrop i.FEer-success-icon:before{
    content: "";
    position: absolute;
    left: 16px;
    top: 10px;
    width: 20px;
    height: 35px;
    border: 3px solid #fff;
    border-top: 0;
    border-left: 0;
    transform: rotate(45deg);
}
#FEerloading .backDrop i.FEer-failed-icon:before{
    content: "";
    position: absolute;
    left: 24px;
    top: 10px;
    width: 3px;
    height: 35px;
    transform: rotate(45deg);
    background: #fff;
}
#FEerloading .backDrop i.FEer-failed-icon:after{
    content: "";
    position: absolute;
    left: 24px;
    top: 10px;
    width: 3px;
    height: 35px;
    transform: rotate(-45deg);
    background: #fff;
}

调用方式说明:

入参介绍:opt: {
    text: opt.text || "加载中..",
    duration: opt.duration || 300,
    type: opt.type || ‘loading‘
}opt对象的参数字段:text,你需要显示提示的文字;duration,自动显示/隐藏 提示的时间间隔;type,提示类型 ‘loading‘ | ‘success‘ | ‘failed‘ 每个类型对应一种提示的样式

原型方法:

show() ,即显示提示;
show() ,隐藏提示;

autoHide() ,自动显示隐藏提示;

调用举例:

var fnotice = new FEerNotice({  text: "加载中..",  duration: 2000,  type: "loading"})fnotice.autoHide()

  

时间: 2024-08-01 22:46:04

简单的移动端提示插件的相关文章

自己写的一个简单的jQuery提示插件

代码: /** * 2014年11月13日 * 提示插件 */ (function ($) { $.fn.tips = function (text) { var divtipsstyle = "position: absolute; left: 0; top: 0; background-color: #dceaf2; padding: 3px; border: solid 1px #6dbde4; visibility: hidden; line-height:20px; "; $

移动端分享插件使用总结

https://www.cnblogs.com/milo-wjh/p/6796082.html 对于分享插件来说,大家肯定都很熟悉,最常用的就是百度分享.jiathis分享等,可分享的媒体也非常多,当然最常用的需求无非也就新浪微博.QQ空间.QQ好友.微信朋友圈.微信好友,其他什么乱七八糟的人人网.猫扑.豆瓣就不多做考虑了,插件内的更多选项列出来有20多个... 既然插件功能已经这么完善了,那还有什么好说的,看看文档就能解决了还有什么好总结的? 但是,问题来了,以上的插件在微信分享时,都是生成一

Jquery 提示插件

jQuery信息提示工具 官方地址:http://www.sharejs.com/code/jquery/plugin/poshytip-1.0/demo/index.html Demo中提供了三种使用的例子,页面代码如下:  <p>1.<a id="tip1" title="嗨..这里有个工具提示条!" href="#">鼠标滑上这里看看</a></p> <br/> <p>

jQuery打造智能提示插件二(可编辑下拉框)

在上一篇 jQuery打造智能提示插件 上改进,增加下拉按钮,修复点击下拉区域外不隐藏BUG 效果 下拉按钮素材: js封装,注意红色部分为BUG修复,然后传入boxwidth不带px: /* /// <reference path="jquery-autocomplete2.0.js" /> zhangs 20140516 */ (function($) { $.fn.combox = function(options) { var KEY = { UP: 38, DOW

jQuery提示插件alertify使用指南!

jQuery提示插件alertify使用指南 alertifyjs是一个非侵入式,可定制的JavaScript通知组件.包括可定制的对话框,和右下角消息弹出框.完全可定制的警报,确认和提示对话框.完全自定义的通知系统.回调参数处理包括"确定"和"取消"按钮的点击.允许对话框排队 1.alertify插件功能 主要实现提示功能,用于代替js中的alert,confirm,prompt,显示友好的提示框 2.alertify使用方法 1.使用的文件 主要使用三个文件,两

从零开始学习jQuery (十一) 实战表单验证与自动完成提示插件

原文:从零开始学习jQuery (十一) 实战表单验证与自动完成提示插件 本系列文章导航 从零开始学习jQuery (一) 开天辟地入门篇 从零开始学习jQuery (二) 万能的选择器 从零开始学习jQuery (三) 管理jQuery包装集 从零开始学习jQuery (四) 使用jQuery操作元素的属性与样式 从零开始学习jQuery (五) 事件与事件对象 从零开始学习jQuery (六) jQuery中的Ajax 从零开始学习jQuery (七) jQuery动画-让页面动起来! 从零

jquery 提示插件 cluetip

jquery的 插件cluetip, 地址下载是:plugins.learningjquery.com/cluetip/demo/ 下面简单讲解下用法: 1 首先当然要放JQUERY的基本JS,和这个插件的JS了,如: <a class="title" href="#" title="This is the title|The first set of contents comes after the first delimiter..... $('

jQuery打造智能提示插件

插件根据实际需要在单功能上封装的,实现传入后台数据地址,要保存值的input,前台要传入的参数(过滤条件),来返回下拉提示数据,数据过多可上下滚动选择,选择后显示文本与对应的值,供后台操作,如图: js封装: /* /// <reference path="jquery-autocomplete2.0.js" /> zhangs 20140516 */ (function($) { $.fn.combox = function(options) { var KEY = {

Jquery消息提示插件toastr使用详解

toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 html <script src="<%=path%>/res/toastr/toastr.min.js"></script> <link rel="stylesheet" href="<%=path%>/res/toastr/toastr