javascript+html5+css3自定義提示窗口
更新時間:2017年06月21日 10:47:42 作者:冷月葬殘花
這篇文章主要為大家詳細(xì)介紹了javascript+html5+css3自定義提示窗口,具有一定的參考價值,感興趣的小伙伴們可以參考一下
javascript自定義提示窗口效果圖:
源碼:
1.demo.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>自定義提示窗口</title> <script type="text/javascript" src="js/myAlert.js"></script> <script type="text/javascript"> function bodyOnload() { var myInput = document.getElementById("myInput"); myInput.style.border = "none"; myInput.style.backgroundColor = "rgba(223, 230, 223, 0.3)"; myInput.value = "請輸入你的名字:"; myInput.onfocus = function () { myInput.style.outline = "none"; myInput.value = ""; }; var image_div = document.createElement("div"); image_div.style.width = myInput.offsetHeight ; image_div.style.height = myInput.offsetHeight; image_div.style.float = "right"; image_div.style.cursor = "pointer"; image_div.onclick = function () { new MyAlert().alert("系統(tǒng)提示","click the image_div",5000); }; var outer_div = document.createElement("div"); outer_div.style.border = "1px solid red"; outer_div.style.width = parseInt(myInput.offsetWidth) + parseInt(image_div.style.width); outer_div.style.height = myInput.offsetHeight; document.body.appendChild(outer_div); outer_div.appendChild(myInput); outer_div.appendChild(image_div); } </script> </head> <body onload="bodyOnload()"> <input id="myInput" type="text" name="name" title="名字"/> </body> </html>
2.myAlert.js
/** * Created by zhuwenqi on 2017/6/20. */ /** * @param options 基本配置 * @constructor */ function MyAlert(options) { this.options = options ; } /** * 提示窗口 * @param title 提示標(biāo)題,默認(rèn)為"" * @param content 提示內(nèi)容,默認(rèn)為"" * @param closeTime 提示窗口自動關(guān)閉時間,單位為ms,默認(rèn)為2000ms */ MyAlert.prototype.alert = function (title,content,closeTime) { var div_background = document.createElement("div"); div_background.style.position = "absolute"; div_background.style.left = "0"; div_background.style.top = "0"; div_background.style.width = "100%"; div_background.style.height = "100%"; div_background.style.backgroundColor = "rgba(0,0,0,0.1)"; div_background.style.zIndex = "1001"; var div_alert = document.createElement("div"); div_alert.style.position = "absolute"; div_alert.style.left = "40%"; div_alert.style.top = "0"; div_alert.style.width = "20%"; div_alert.style.height = "20%"; div_alert.style.overflow = "auto"; div_alert.style.backgroundColor = "rgba(255,255,255,0.5)"; div_alert.style.zIndex = "1002"; div_alert.style.border = "1px solid blue"; div_alert.style.borderRadius = "10px"; div_alert.style.boxShadow = "0 0 10px gray"; var div_title = document.createElement("div"); div_title.style.backgroundColor = "rgba(0,255,0,0.3)"; div_title.style.textAlign = "center"; var span_title = document.createElement("span"); span_title.style.fontSize = "20px"; span_title.style.fontWeight = "bold"; var text_title = document.createTextNode((title === undefined || title === null) ? "" : title) ; span_title.appendChild(text_title); div_title.appendChild(span_title); div_alert.appendChild(div_title); var div_content = document.createElement("div"); div_content.style.lineHeight = "35px"; div_content.style.paddingLeft = "10px"; var span_content = document.createElement("span"); var text_content = document.createTextNode((content === undefined || content === null) ? "" : content); span_content.appendChild(text_content); div_content.appendChild(span_content); div_alert.appendChild(div_content); document.body.appendChild(div_background); document.body.appendChild(div_alert); setTimeout(function () { document.body.removeChild(div_alert); document.body.removeChild(div_background); },(closeTime === undefined || closeTime === null || closeTime === "") ? 2000 : closeTime); };
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序?qū)崿F(xiàn)動態(tài)設(shè)置placeholder提示文字及按鈕選中/取消狀態(tài)的方法
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)動態(tài)設(shè)置placeholder提示文字及按鈕選中/取消狀態(tài)的方法,涉及事件綁定及this.setData動態(tài)設(shè)置屬性數(shù)據(jù)的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12javascript 瀏覽器類型和版本號檢測代碼(兼容多瀏覽器)
果對javascript了解不是特別深入的話,很容易就會寫出不兼容的代碼(就像我),這時候就得判斷瀏覽器了。比如事件偵聽、一些鼠標(biāo)和鍵盤事件、Range等,一些都會不一樣.下面列出幾種常用的檢測瀏覽器方法,以饗觀眾!2010-04-04一文詳解JS中的Map、Set、WeakMap和WeakSet
在JavaScript中,Map、Set、WeakMap和WeakSet是四個不同的數(shù)據(jù)結(jié)構(gòu),它們都有不同的特點和用途,本文詳細(xì)介紹了Map、Set、WeakMap和WeakSet的用法及區(qū)別,需要的朋友可以參考下2023-04-04JS檢測頁面中哪個HTML標(biāo)簽觸發(fā)點擊事件的方法
這篇文章主要介紹了JS檢測頁面中哪個HTML標(biāo)簽觸發(fā)點擊事件的方法,涉及javascript頁面元素事件響應(yīng)機(jī)制,需要的朋友可以參考下2016-06-06Javascript 鼠標(biāo)移動上去小三角形滑塊緩慢跟隨效果
一個tab選項卡,當(dāng)鼠標(biāo)移動上去時紅色滑塊跟隨,在布局過程中經(jīng)常會使用到,本文提供了詳細(xì)的實現(xiàn)代碼,感興趣的朋友可以參考下2013-04-04JS使用百度地圖API自動獲取地址和經(jīng)緯度操作示例
這篇文章主要介紹了JS使用百度地圖API自動獲取地址和經(jīng)緯度操作,結(jié)合實例形式分析了javascript與百度地圖API接口交互實現(xiàn)獲取地址與經(jīng)緯度相關(guān)操作技巧,需要的朋友可以參考下2019-04-04