<style>
*{margin:0;padding:0;}
.cont{
width:600px;
height:500px;
border:1px solid #cccc;
margin:100px auto;
position:relative;
}
.list{
margin-left:100px;
position: absolute;
}
.list li{
list-style: none;
width:400px;
height:80px;
background:rgb(177, 223, 235);
border-radius: 5px;
margin-bottom: 10px;
border:1px solid yellowgreen;
line-height: 80px;
text-align: center;
}
.box{
width:300px;
height:140px;
border-radius: 5px;
position:absolute;
border:1px solid #000;
background:#ccc;
left:150px;
bottom:40px;
margin: 0;padding: 0;
display: none;
}
.box p{
text-align: center;
height:20px;
background:orange;
line-height: 20px;
border-radius: 5px;
}
.form *{
border:none;
padding:0;margin:0;
float:left;
height:80px;
width:280px;
margin-left:10px;
margin-top: 5px;
}
.box input{
width:80px;
height:26px;
border-radius: 5px;
border:none;
margin:5px;
margin-left:45px;
}
#ok{
background:orange;
}
#txt{
outline:none;
resize:none;
}
.btn1{
width:16px;
height:16px;
border-radius: 3px;
background:#ccc;
position: absolute;
right:0;
top:0;
text-align: center;
line-height: 16px;
}
.black {
width: 600px;
height: 500px;
position: absolute;
top: 0;
left: 0;
background-color: rgba(101, 101, 101, 0.6);
opacity: 1;
transition: all 1s;
display: none;
}
</style>
</head>
<body>
<div class="cont">
<button id="btn">添加</button>
<ul class="list">
<li>人核工程与德国回复日俄</li>
<li>无房户二无房户</li>
<li>日本狗和头脑糊涂</li>
<li>过让她和她</li>
<li>额日哦韩国i哦让他</li>
</ul>
<div class="black">
</div>
<div class="box">
<p class="title">弹出窗口
</p>
<span class="btn1">x</span>
<div class="form">
<textarea name="" id="txt"></textarea>
</div>
<input type="button" value="确定" id="ok">
<input type="button" value="取消" id="no">
</div>
</div>
<script>
var btn = document.querySelector("#btn")
var box = document.querySelector(".box")
var title = document.querySelector(".title")
var cont = document.querySelector(".cont")
var ok = document.querySelector("#ok")
var no = document.querySelector("#no")
var btn1 = document.querySelector(".btn1")
var txt = document.querySelector("#txt")
var lis = document.querySelectorAll(".list li")
var black = document.querySelector(".black")
btn.onclick = function(){
box.style.display = "block"
black.style.display = "block"
}
no.onclick = function(){
box.style.display = "none"
black.style.display = "none"
txt.value = ""
}
btn1.onclick = function(){
box.style.display = "none"
black.style.display = "none"
txt.value = ""
}
title.onmousedown = function(e){
var e = e || window.event
var disX = e.offsetX
var disY = e.offsetY
document.onmousemove = function(e){
var e = e || window.event
var left = e.clientX - cont.offsetLeft - disX
var top = e.clientY - cont.offsetTop - disY
if(left <= 0) left = 0
if(top <= 0) top = 0
if(left >= cont.offsetWidth - box.offsetLeft) left = cont.offsetWidth - box.offsetLeft
if(top >= cont.offsetHeight - box.offsetHeight) top = cont.offsetHeight - box.offsetHeight
box.style.left = left+ "px"
box.style.top = top + "px"
}
document.onmouseup = function(){
document.onmousemove = null
document.onmouseup = null
}
stopDefault(e)
}
var num = 0
ok.onclick = function(){
if(txt.value.length >= 150){
alert("不能超过150个字")
}else{
if(num < lis.length){
lis[num].innerHTML = txt.value
}else{
lis[num - lis.length].innerHTML = txt.value
}
}
txt.value = ""
num++
box.style.display = "none"
black.style.display = "none"
}
function stopDefault(e){
if(e.preventDefault){
e.preventDefault()
}else{
e.returnValue = false
}
}
</script>
留言板案例
最新推荐文章于 2022-08-27 16:47:43 发布