如果你厌倦了简单粗暴的alert()和confirm(),请试试更易定制的Simple Popup

Demo

Usage

  • jQuery version

  1. Firstly, introduce jQuery(1.5+) into your page.

  2. Then, introduce assets(js + css) of Simple Popup into your page.

  3. Finally, replace any alert(), confirm() and prompt() method in page with simplePopup() method on page.

native javascript version

  1. First, introduce assets(js + css, obviously, both of the two version use the same css file) of Simple Popup into your page.

  2. Then, replace any alert(), confirm() and prompt() method in page with simplePopup()


built-in alert box

alert('An exception occurred.');
event.target.nextElementSibling.textContent = 'The application has just got an exception.';

Simple Popup alternative of jquery version

var alertBox = simplePopup(0, 'An exception occurred.');
$.when(alertBox).then(function() {
  $(event.target).next().text('The application has just got an exception.');
});

Simple Popup alternative of javascript version

simplePopup(0, 'An exception occurred.').then(function() {
  event.target.nextElementSibling.textContent = 'The application has just got an exception.';
});

built-in prompt box

var res = confirm('It\'s time to change. Do you agree with me?');
if (res) {
  event.target.nextElementSibling.textContent = 'Yes, let\'s go for it.';
} else {
  event.target.nextElementSibling.textContent = 'No, this is not the time.';
}

Simple Popup alternative of jquery version

var confirmBox = simplePopup(1, 'It\'s time to change. Do you agree with me?');
$.when(confirmBox).then(function(res) {
    if (res) {
      $(event.target).next().text('Yes, let\'s go for it.');
  } else {
    $(event.target).next().text('No, this is not the time.');
  }
});

Simple Popup alternative of javascript version

simplePopup(1, 'It\'s time to change. Do you agree with me?').then(function(res) {
  if (res) {
    event.target.nextElementSibling.textContent = 'Yes, let\'s go for it.';
    } else {
    event.target.nextElementSibling.textContent = 'No, this is not the time.';
    }
});

built-in prompt box

var username = prompt('Please enter your username', 'Michael Jordan');
if (username != null && username != '') {
  event.target.nextElementSibling.textContent = username + ', hey, welcome back.';
}

Simple Popup alternative of jquery version

var promptBox = simplePopup(2, 'Please enter your username', 'Michael Jordan');
$.when(promptBox).then(function(res) {
  if (res) {
    $(event.target).next().text(res + ', hey, welcome back.');
  } else {
    $(event.target).next().text('Anoymous user logs in.');
  }
});

Simple Popup alternative of javascript version

simplePopup(2, 'Please enter your username', 'Michael Jordan').then(function(res) {
  if (res) {
    event.target.nextElementSibling.textContent = res + ', hey, welcome back.';
  } else {
    event.target.nextElementSibling.textContent = 'Anoymous user logs in.';
  }
});

killer Feature

  1. When you toggle the popup boxes with simpelPopup() method, the overlayed background keeps its position just where it was.

  2. As you can see above, this plugin help you rewrite the current code With the least code modifications.

Browser Support

1. Simple Popup of jquery version

  • Chrome 8.0+

  • Firefox 3.6+

  • Safari 3.1.2+

  • Opera 9.64+

2. Simple Popup of javascript version

  • Chrome 32.0+

  • Firefox 29.0+

  • Safari 7.1+

  • Opera 19+


转载于:https://my.oschina.net/dabeng/blog/625934

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值