我有 4 个隐藏的部分 div,单击时它们应该全部显示在页面中央,但是最后一个显示得比其他部分更靠下,我知道这是由于弹性框的性质造成的,但最好的方法是什么确保它们都出现在完全相同的位置?
JS - 另一个问题,这个脚本...是否有更有效的方法来编写它,因为我觉得它的功能有点麻烦,我只是不确定如何编写它。
function about() {
var about = document.getElementById("about");
var contact = document.getElementById("contact");
var work = document.getElementById("work");
var blog = document.getElementById("blog");
if (about.style.visibility === "hidden") {
about.style.visibility = "visible";
contact.style.visibility = "hidden";
work.style.visibility = "hidden";
blog.style.visibility = "hidden";
} else {
about.style.visibility = "hidden";
}
}
function contact() {
var about = document.getElementById("about");
var contact = document.getElementById("contact");
var work = document.getElementById("work");
var blog = document.getElementById("blog");
if (contact.style.visibility === "hidden") {
contact.style.visibility = "visible";
about.style.visibility = "hidden";
work.style.visibility = "hidden";
blog.style.visibility = "hidden";
} else {
contact.style.visibility = "hidden";
}
}
function work() {
var about = document.getElementById("about");
var contact = document.getElementById("contact");
var work = document.getElementById("work");
var blog = document.getElementById("blog");
if (work.style.visibility === "hidden") {
work.style.visibility = "visible";
about.style.visibility = "hidden";
contact.style.visibility = "hidden";
blog.style.visibility = "hidden";
} else {
work.style.visibility = "hidden";
}
}
function blog() {
var about = document.getElementById("about");
var contact = document.getElementById("contact");
var work = document.getElementById("work");
var blog = document.getElementById("blog");
if (blog.style.visibility === "hidden") {
blog.style.visibility = "visible";
about.style.visibility = "hidden";
contact.style.visibility = "hidden";
work.style.visibility = "hidden";
} else {
blog.style.visibility = "hidden";
}
}
慕侠2389804
SMILET
相关分类