html, body {
margin: 0;
padding: 0;
background: #f2f1f6;
}
.container {
position: relative;
width: 500px;
height: 300px;
background: #f2f1f6;
}
.container h1 {
margin-top: 0;
}
.container img {
vertical-align: -70px;
text-align:center;
}
.bd {
padding-left: 30px;
color:red;
}
.ft {
position: absolute;
width: 100%;
bottom: 20px;
padding: 0 30px;
line-height: 30px;
box-sizing: border-box;
}
.btn-group {
float: left;
}
.fr {
margin-top:30px;
float: right;
}
button {
cursor: pointer;
}
#p1 {
}
.not-allow {
position: relative;
}
#p2 {
display: none;
}
.red {
margin: 0;
font-size: 24px;
padding: 30px 40px;
color: red;
letter-spacing: 4px;
}
.wavy {
text-decoration: underline;
text-decoration-style: wavy;
}
.name {
padding-left: 10px;
}
.btn {
padding: 6px 12px;
}
.a{
width:600px;
height:500px;
margin:0 auto;
margin-top:100px;
}
.allow{
position:absolute;
top:150px;
}
.not-allow{
position:absolute;
left:100px;
top:150px;
}
.b{
position:absolute;
left:400px;
top:80px;
}
样式: ript:
function an(){
var bu=document.getElementById("bu");
alert("此功能无效!!!");
}
(function(){
function $(selector) {
return document.querySelector(selector);
}
var $p1 = document.getElementById('p1');
var $p2 = document.getElementById('p2');
var $container = $('.container');
var $btn = $('#but');
var isBlockClose = true;
var maxX = $container.clientWidth - 1, maxY = $container.clientHeight - 1;
var originPos = $btn.getBoundingClientRect();
$('.allow').addEventListener('click', function() {
$p1.style.display = 'none';
$p2.style.display = 'block';
});
$btn.addEventListener('mouseover', function() {
this.style.left = Math.floor(Math.random() * maxX - originPos.left) + 'px';
this.style.top = Math.floor(Math.random() * maxY - originPos.top) + 'px';
});
$('.exit').addEventListener('click', function() {
isBlockClose = false;
window.close();
});
window.addEventListener('beforeunload', function(e) {
if (isBlockClose) {
alert("此路不通");
e.returnValue = false;
e.preventDefault();
return "此路不通";
}
});
})();