代码描述:JavaScript 移动端 弹出提示窗口 代码实例。JavaScript移动端弹出提示窗口代码实例
分享一段代码实例,它实现了移动端点击弹出提示窗口的效果。 代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51qianduan.com/" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"/> <title>51前端</title> <style type="text/css"> * { margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; -webkit-overflow-scrolling: touch; font-family: "Helvetica Neue",Helvetica,"songti",STHeiTi,sans-serif; font-size: 16px; } .main { width: 332px; height: auto; margin: 100px auto; } .input { width: 300px; padding: 10px 15px; border: 1px solid #ddd; border-radius: 4px; -webkit-appearance: none; } .button { outline: none; -webkit-appearance: none; border: none; color: #fff; font-size: 18px; width: 300px; height: 46px; background: #189cfb; border-radius: 4px; margin-top: 30px; -webkit-transition: 0.3s; cursor: pointer; } .button:active { background: #1170b4; } /*不想多写ie等浏览器兼容的分割线*/ .alert { min-width: 10px; max-width: 280px; position: fixed; bottom: 80px; background: rgba(0,0,0,0.6); border-radius: 6px; color: #eee; font-size: 16px; padding: 10px 15px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.3); left: 50%; -webkit-transform: translate3d(-50%,0,0); -webkit-animation: alert 4s; } @-webkit-keyframes alert { 0% { -webkit-transform: translate3d(-50%,0,0); opacity: 0; } 10% { -webkit-transform: translate3d(-50%,-30px,0); } 15% { -webkit-transform: translate3d(-50%,-25px,0); opacity: 1; } 100% { -webkit-transform: translate3d(-50%,-25px,0); } } </style> </head> <body> <div class="main"> <input type="search" class="input" value="51前端"> <button class="button" id="btn">查看效果</button> </div> <script type="text/javascript"> var btn = document.querySelector('#btn'); btn.onclick = function() { var t = document.querySelector('input').value; msg.alert(t) } var msg = { alert: function(t) { var alt = document.querySelector('.alert'); if (alt) { alt.innerHTML = t; return; }; var h = document.createElement('div'); h.innerHTML = t || '为什么不说话 (╰_╯)'; h.setAttribute('class', 'alert'); document.querySelector('body').appendChild(h); msg.fire(h); }, fire: function(obj) { var evt = ['webkitAnimationEnd', 'mozAnimationEnd', 'msAnimationEnd', 'oAnimationEnd', 'animationEnd']; for (var index = 0; index < evt.length; index++) { obj.addEventListener(evt[index], function() { this.parentNode.removeChild(this); }); } } }; </script> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能