原生js实现自适应提示框弹出效果
代码语言:html
所属分类:弹出层
代码描述:原生js实现自适应提示框弹出效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <style> @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700"); .msgbox-area { max-height: 100%; position: fixed; bottom: 15px; left: 20px; right: 20px; } .msgbox-area .msgbox-box { font-size: inherit; color: #ffffff; background-color: rgba(0, 0, 0, 0.8); padding: 18px 20px; margin: 0 0 15px; display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; position: relative; border-radius: 12px; box-shadow: 0 10px 15px rgba(0, 0, 0, 0.65); -webkit-transition: opacity 300ms ease-in; transition: opacity 300ms ease-in; } .msgbox-area .msgbox-box.msgbox-box-hide { opacity: 0; } .msgbox-area .msgbox-box:last-child { margin: 0; } .msgbox-area .msgbox-content { flex-shrink: 1; } .msgbox-area .msgbox-close { color: #ffffff; font-weight: bold; text-decoration: none; margin: 0 0 0 20px; -webkit-box-flex: 0; flex-grow: 0; flex-shrink: 0; position: relative; -webkit-transition: text-shadow 225ms ease-out; transition: text-shadow 225ms ease-out; } .msgbox-area .msgbox-close:hover { text-shadow: 0 0 3px #efefef; } @media (min-width: 481px) and (max-width: 767px) { .msgbox-area { left: 80px; right: 80px; } } @media (min-width: 768px) { .msgbox-area { width: 480px; height: 0; top: 15px; left: auto; right: 15px; } } body { font-family: "Open Sans", sans-serif; } .msgbox-area { font-size: 16px; } .msgbox-message-container { text-align: center; width: 100vw; height: 100vh; padding: 20px; box-sizing: border-box; display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: center; justify-content: center; -webkit-box-orient: vertical; -webkit-box-direction: normal; flex-direction: column; } .msgbox-message-container h1, .msgbox-message-container h3 { margin: 10px 20px; } .msgbox-message-container p { margin: 5px 20px; } .msgbox-message-button { font-size: 18px; font-weight: bold; font-family: inherit; color: white; background-color: #1476ff; width: 250px; border: solid 2px #005de0; padding: 10px 20px; cursor: pointer; outline: none; box-shadow: 0 5px #005de0; -webkit-transition: background-color 100ms ease-out, box-shadow 100ms ease-out, -webkit-transform 100ms ease-out; transition: background-color 100ms ease-out, box-shadow 100ms ease-out, -webkit-transform 100ms ease-out; transition: background-color 100ms ease-out, box-shadow 100ms ease-out, transform 100ms ease-out; transition: background-color 100ms ease-out, box-shadow 100ms ease-out, transform 100ms ease-out, -webkit-transform 100ms ease-out; } .msgbox-message-button:hover, .msgbox-message-button:focus, .msgbox-message-button:active { background-color: #2e85ff; } .msgbox-message-button:active { background-color: #0068fa; box-shadow: 0 0 #005de0; -webkit-transform: translateY(5px); transform: translateY(5px); } </style> </head> <body translate="no"> <div class="msgbox-message-container"> <h1>自适应提示框</h1> <h3>Using Native Javascript class</h3> <p><button id="msgboxPersistent" class="msgbox-message-button" type="button">Show persistent</button></p> <p><button id="msgboxShowMessage" class="msgbox-message-button" type="button">Show non-persistent</button></p> <p><button id="msgboxHiddenClose" class="msgbox-message-button" type="button">Hidden close button</button></p> </div> <div id="msgbox-area" class="msgbox-area"></div> <script> class MessageBox { constructor(id, option) { this.id = id; this.option = option; } show(msg, label = "CLOSE", callback = null) { if (this.id === null || typeof this.id === "undefined") { // if the ID is not set or if the ID is undefined throw "Please set the 'ID' of the message box container."; } if (msg === "" || typeof msg .........完整代码请登录后点击上方下载按钮下载查看
网友评论0