<!--弹出框HTML代码及调用示例-->
<button type="button" onclick="showconfirm()">弹出confirm</button>
<div id="niunan-confirm" class="niunan-confirm" style="display:none;">
<div class="message">
<div>温馨提示</div>
<div>是否确认删除?</div>
<div>
<button type="button" onclick="onChoose(1)">确认</button>
<button type="button" onclick="onChoose(0)">取消</button>
</div>
</div>
</div>
/*confirm弹出框的样式*/
@keyframes message-show {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.niunan-confirm {
animation: message-show 0.3s;
top: 0;
z-index: 2000;
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(50,50,50,0.2);
}
.niunan-confirm>.message {
position: absolute;
z-index: 2001;
box-shadow: 0 0 10px rgba(233,150,122,0.3);
width: 80%;
min-height: 100px;
border-radius: 3px;
top: calc(50% - 50px);
left: 10%;
background-color: white;
text-align: center;
border: 1px solid rgba(233, 150, 122, 0.3)
}
.niunan-confirm>.message > div:first-child {
margin: 10px 0 20px 0;
padding-left: 10px;
text-align: left;
font-size: 18px;
font-weight: bold;
border-bottom: 1px solid rgba(233, 150, 122, 0.3);
}
.niunan-confirm> .message > div:last-child {
margin: 10px 0 10px 0;
padding-top: 10px;
font-size: 14px;
}
.niunan-confirm> .message > div:last-child > button {
padding: 3px 10px;
}
.niunan-confirm> .message > div:last-child > button:first-child {
margin-right: 30px;
background: #f0c14b;
background: linear-gradient(to bottom,#f7dfa5,#f0c14b);
border-color: #f7dfa5;
}
/*弹出confirm的javascript代码 */
function showconfirm() {
const confirmEle = document.getElementById('niunan-confirm')
confirmEle.style.height = getDocumentHeight() + "px";//设置遮罩的整体高度和整个文档高度一样
const messageEle = confirmEle.getElementsByClassName("message")[0];
const y = window.scrollY; //计算滚动条的高度
const windowh = window.innerHeight; //当前窗口的高度
messageEle.style.top = y + (windowh / 2) + "px"; //设置里面那个弹出窗口正好在屏幕中间
confirmEle.style.display = 'block';
}
function onChoose(i) {
if (i > 0) {
alert('您点了确认按钮');
} else {
alert('您点了取消按钮');
}
document.getElementById('niunan-confirm').style.display = 'none';
}
function getDocumentHeight() {
const h = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight,
document.body.clientHeight,
document.documentElement.clientHeight
);
console.log("整个文档高度",h);
return h;
}
/*niunan-toast 样式*/@keyframes niunant-toast-show {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.niunan-toast {
animation: niunant-toast-show 0.5s;
position: absolute;
width: 100px;
height: 60px;
line-height: 60px;
border-radius: 3px;
background-color: rgba(50,50,50,0.7);
top: calc(50% - 30px); /*注意减号两边要各有一个空格*/
left: calc(50% - 50px);
color: white;
font-size: 14px;
font-weight: bold;
text-align: center;
z-index: 2000
}
/*niunan-toast javascript脚本*/
function showtoast() {
//<div id='niunan-toast' class='niunan-toast'>登录成功</div>
const newDiv = document.createElement("div");
newDiv.className = "niunan-toast";
newDiv.id = "niunan-toast";
newDiv.textContent = "登录成功";
const y = window.scrollY; //计算滚动条的高度
const windowh = window.innerHeight; //当前窗口的高度
newDiv.style.top = y + (windowh/2) + "px";
document.body.appendChild(newDiv);
//1.5秒后弹出的框框消失
var timeout = setTimeout(() => {
document.getElementById("niunan-toast").remove();
}, 1500);
}
<!--niunan-toast调用示例--><button type="button" onclick="showtoast()">点击显示</button>
<!--复选框样式的HTML代码,要引入那个open-iconic图标库 --><div class="niunan-chk">
<label for="chkremeber">点本行文字打勾勾</label>
<input type="checkbox" name="chkremeber" id="chkremeber">
<div><span class="oi oi-check"></span></div>
</div><link rel="stylesheet" href="/css/open-iconic/font/css/open-iconic-bootstrap.min.css">
/*复选框样式代码*/div.niunan-chk > label {
font-weight: normal;
line-height: 30px;
margin-left: 10px;
width: calc(100%-35px);
font-size: 25px;
}
/*原生复选框隐藏,只能靠点击label文字来选择复选框*/
div.niunan-chk > input {
display: none;
}
/*复选框选中,相应的勾勾图标显示*/
div.niunan-chk > input:checked + div > span {
display: inline-block;
}
div.niunan-chk > div {
display: inline-block;
float: left;
border: 1px solid #818DFF;
border-radius: 3px;
width: 30px;
height: 30px;
text-align: center;
}
div.niunan-chk > div > span {
display: none;
margin-top: 1px;
color: #4B5BF1;
font-size: 25px;
}
.niunan-btn-yellow {
height: 50px;
background-color: #f0c14b;
background: linear-gradient(to bottom, #f7dfa5, #f0c14b);
border-color: #f7dfa5;
color: black;
font-size: 16px;
padding: 10px 30px;
margin: 10px 0;
}
.niunan-btn-blue {
border-radius: 5px;
padding: 10px 30px;
height: 50px;
color: white;
font-size: 16px;
cursor: pointer;
transition: all .3s;
cursor: move;
background: linear-gradient(180deg, #818DFF 0%, #4B5BF1 100%);
box-shadow: 0px 4px 12px 0px rgba(75, 91, 241, 0.24), 0px 1px 2px 0px rgba(40, 52, 166, 0.24);
border-color: #818DFF;
}
.niunan-btn-red{
border-radius: 5px;
padding: 10px 30px;
height: 50px;
color: white;
font-size: 16px;
cursor: pointer;
transition: all .3s;
cursor: move;
background: linear-gradient(180deg, #FF9F9F 0%, #D72A2A 100%);
box-shadow: 0px 4px 12px 0px rgba(75, 91, 241, 0.24), 0px 1px 2px 0px rgba(40, 52, 166, 0.24);
border-color: #FF9F9F;
}
<!--返回顶部的HTML代码,记得引入open-iconic-->
<div class="niunan-backtop" onclick="window.scrollTo(0,0)">
<span class="oi oi-arrow-thick-top" aria-hidden="true"></span>
</div>
/*返回顶部的样式*/
.niunan-backtop {
width: 45px;
height: 45px;
text-align:center;
border-radius: 5px;
background: rgba(50, 50, 50, 0.4);
position: fixed;
right: 10px;
bottom: 20px;
}
.niunan-backtop > span {
font-size: 28px;
line-height: 45px;
color: white;
}