直接实例:
//逃逸按钮初始位置
.mobileButtonOne {
position: absolute;
top: 10%;
left: 47%;
}
//初始隐藏真实按钮
.mobileButton {
display: none;
}
<button type="button" class="btn btn-primary mobileButtonOne" id="mobileButton">逃逸按钮</button>
<button type="button" class="btn btn-primary mobileButton" id="seriousButton">真实按钮</button>
var mobileNumber = 0;
$("#mobileButton").click(function() {
let mobiletop = Math.round(Math.random() * 90);
let mobileLeft = Math.round(Math.random() * 90);
if (mobileNumber > 0) { //逃逸次数
$("#seriousButton").css({
"position": "absolute",
"top": mobiletop + "%",
"left": mobileLeft + "%",
"display": "block",
});
$("#mobileButton").css("display", "none")
} else {
$("#mobileButton").css({
"position": "absolute",
"top": mobiletop + "%",
"left": mobileLeft + "%",
});
mobileNumber++;
}
});