新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍了javascript+html5+css3自定义提示窗口的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
我们提供的服务有:网站设计、做网站、微信公众号开发、网站优化、网站认证、邕宁ssl等。为上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的邕宁网站制作公司
javascript自定义提示窗口效果图:
源码:
1.demo.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>自定义提示窗口
2.myAlert.js
/** * Created by zhuwenqi on 2017/6/20. */ /** * @param options 基本配置 * @constructor */ function MyAlert(options) { this.options = options ; } /** * 提示窗口 * @param title 提示标题,默认为"" * @param content 提示内容,默认为"" * @param closeTime 提示窗口自动关闭时间,单位为ms,默认为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); };
感谢你能够认真阅读完这篇文章,希望小编分享的“javascript+html5+css3自定义提示窗口的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!