gpt4 book ai didi

javascript - 为什么在我添加该功能时我的时间线没有消失又重新出现?

转载 作者:行者123 更新时间:2023-11-28 00:36:32 25 4
gpt4 key购买 nike

所以我正在通过 this guide 制作时间表我正在添加交互性,然后是隐藏和显示部分。但我的时间线不会消失,只是停留在那里不动,有谁知道我该如何解决这个问题,实际上可以让它首先消失,然后在你向下滚动页面时让它出现?

.timeline ul li {
list-style-type: none;
position: relative;
width: 6px;
margin: 0 auto;
padding-top: 50px;
background: black;
}

.timeline ul li::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 30px;
height: 30px;
border-radius: 50%;
background: inherit;
}

.timeline ul li div {
position: relative;
bottom: 0;
width: 400px;
padding: 15px;
background: #F45B69;
}

.timeline ul li div::before {
content: '';
position: absolute;
bottom: 7px;
width: 0;
height: 0;
border-style: solid;
}

.timeline ul li:nth-child(odd) div {
left: 45px;
}

.timeline ul li:nth-child(odd) div::before {
left: -15px;
border-width: 8px 16px 8px 0;
border-color: transparent #F45B69 transparent transparent;
}

.timeline ul li:nth-child(even) div {
left: -439px;
}

.timeline ul li:nth-child(even) div::before {
right: -15px;
border-width: 8px 0 8px 16px;
border-color: transparent transparent transparent #F45B69;
}

.timeline ul li::after {
background: #fff;
transition: background .5s ease-in-out;
}

.timeline ul li.in-view::after {
background: #F45B69;
}

.timeline ul li:nth-child(odd) div {
transform: translate3d(200px,0,0);
}

.timeline ul li:nth-child(even) div {
transform: translate3d(-200px,0,0);
}

.timeline ul li.in-view div {
transform: none;
visibility: visible;
opacity: 1;
}

<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>History of the Computer</title>
<script src="history.j"></script>*/
</head>
<body>

<script>
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}

var items = document.querySelectorAll(".timeline li");

// code for the isElementInViewport function

function callbackFunc() {
for (var i = 0; i < items.length; i++) {
if (isElementInViewport(items[i])) {
items[i].classList.add("in-view");
}
}
}

window.addEventListener("load", callbackFunc);
window.addEventListener("scroll", callbackFunc);

</script>



<section class="timeline">
<ul>
<li>
<div>
<time>1801</time> In France, Joseph Marie Jacquard invents a loom that uses punched wooden cards to automatically weave fabric designs. Early computers would use similar punch cards.
</div>
</li>
<li>
<div>
<time>1822</time> English mathematician Charles Babbage conceives of a steam-driven calculating machine that would be able to compute tables of numbers. The project, funded by the English government, is a failure. More than a century later, however, the world's first computer was actually built.
</div>
</li>
<li>
<div>
<time>1890</time> Herman Hollerith designs a punch card system to calculate the 1880 census, accomplishing the task in just three years and saving the government $5 million. He establishes a company that would ultimately become IBM.
</div>
</li>
<li>
<div>
<time>1936</time> Alan Turing presents the notion of a universal machine, later called the Turing machine, capable of computing anything that is computable. The central concept of the modern computer was based on his ideas.
</div>
</li>
<li>
<div>
<time>1937</time> J.V. Atanasoff, a professor of physics and mathematics at Iowa State University, attempts to build the first computer without gears, cams, belts or shafts.
</div>
</li>
<li>
<div>
<time>1939</time> Hewlett-Packard is founded by David Packard and Bill Hewlett in a Palo Alto, California, garage, according to the Computer History Museum.
</div>
</li>
<li>
<div>
<time>1941</time> Atanasoff and his graduate student, Clifford Berry, design a computer that can solve 29 equations simultaneously. This marks the first time a computer is able to store information on its main memory.
</div>
</li>
<li>
<div>
<time>1943-1944</time> Two University of Pennsylvania professors, John Mauchly and J. Presper Eckert, build the Electronic Numerical Integrator and Calculator (ENIAC). Considered the grandfather of digital computers, it fills a 20-foot by 40-foot room and has 18,000 vacuum tubes.
</div>
</li>
<li>
<div>
<time>1946</time> Mauchly and Presper leave the University of Pennsylvania and receive funding from the Census Bureau to build the UNIVAC, the first commercial computer for business and government applications.
</div>
</li>
<li>
<div>
<time>1947</time> William Shockley, John Bardeen and Walter Brattain of Bell Laboratories invent the transistor. They discovered how to make an electric switch with solid materials and no need for a vacuum.
</div>
</li>
<li>
<div>
<time>1953</time> Grace Hopper develops the first computer language, which eventually becomes known as COBOL. Thomas Johnson Watson Jr., son of IBM CEO Thomas Johnson Watson Sr., conceives the IBM 701 EDPM to help the United Nations keep tabs on Korea during the war.
</div>
</li>
</ul>
</section>
</body>
</html>

最佳答案

嗯,乍一看,您似乎遗漏了这段代码:

.timeline ul li div {
visibility: hidden;
opacity: 0;
transition: all .5s ease-in-out;
}

function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}

var items = document.querySelectorAll(".timeline li");

// code for the isElementInViewport function

function callbackFunc() {
for (var i = 0; i < items.length; i++) {
if (isElementInViewport(items[i])) {
items[i].classList.add("in-view");
}
}
}

window.addEventListener("load", callbackFunc);
window.addEventListener("scroll", callbackFunc);
.timeline ul li {
list-style-type: none;
position: relative;
width: 6px;
margin: 0 auto;
padding-top: 50px;
background: black;
}

.timeline ul li::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 30px;
height: 30px;
border-radius: 50%;
background: inherit;
}

.timeline ul li div {
position: relative;
bottom: 0;
width: 400px;
padding: 15px;
background: #F45B69;
}

.timeline ul li div::before {
content: '';
position: absolute;
bottom: 7px;
width: 0;
height: 0;
border-style: solid;
}

.timeline ul li:nth-child(odd) div {
left: 45px;
}

.timeline ul li:nth-child(odd) div::before {
left: -15px;
border-width: 8px 16px 8px 0;
border-color: transparent #F45B69 transparent transparent;
}

.timeline ul li:nth-child(even) div {
left: -439px;
}

.timeline ul li:nth-child(even) div::before {
right: -15px;
border-width: 8px 0 8px 16px;
border-color: transparent transparent transparent #F45B69;
}

.timeline ul li::after {
background: #fff;
transition: background .5s ease-in-out;
}

.timeline ul li.in-view::after {
background: #F45B69;
}

.timeline ul li div {
visibility: hidden;
opacity: 0;
transition: all .5s ease-in-out;
}

.timeline ul li:nth-child(odd) div {
transform: translate3d(200px,0,0);
}

.timeline ul li:nth-child(even) div {
transform: translate3d(-200px,0,0);
}

.timeline ul li.in-view div {
transform: none;
visibility: visible;
opacity: 1;
}
<section class="timeline">
<ul>
<li>
<div>
<time>1801</time> In France, Joseph Marie Jacquard invents a loom that uses punched wooden cards to automatically weave fabric designs. Early computers would use similar punch cards.
</div>
</li>
<li>
<div>
<time>1822</time> English mathematician Charles Babbage conceives of a steam-driven calculating machine that would be able to compute tables of numbers. The project, funded by the English government, is a failure. More than a century later, however, the world's first computer was actually built.
</div>
</li>
<li>
<div>
<time>1890</time> Herman Hollerith designs a punch card system to calculate the 1880 census, accomplishing the task in just three years and saving the government $5 million. He establishes a company that would ultimately become IBM.
</div>
</li>
<li>
<div>
<time>1936</time> Alan Turing presents the notion of a universal machine, later called the Turing machine, capable of computing anything that is computable. The central concept of the modern computer was based on his ideas.
</div>
</li>
<li>
<div>
<time>1937</time> J.V. Atanasoff, a professor of physics and mathematics at Iowa State University, attempts to build the first computer without gears, cams, belts or shafts.
</div>
</li>
<li>
<div>
<time>1939</time> Hewlett-Packard is founded by David Packard and Bill Hewlett in a Palo Alto, California, garage, according to the Computer History Museum.
</div>
</li>
<li>
<div>
<time>1941</time> Atanasoff and his graduate student, Clifford Berry, design a computer that can solve 29 equations simultaneously. This marks the first time a computer is able to store information on its main memory.
</div>
</li>
<li>
<div>
<time>1943-1944</time> Two University of Pennsylvania professors, John Mauchly and J. Presper Eckert, build the Electronic Numerical Integrator and Calculator (ENIAC). Considered the grandfather of digital computers, it fills a 20-foot by 40-foot room and has 18,000 vacuum tubes.
</div>
</li>
<li>
<div>
<time>1946</time> Mauchly and Presper leave the University of Pennsylvania and receive funding from the Census Bureau to build the UNIVAC, the first commercial computer for business and government applications.
</div>
</li>
<li>
<div>
<time>1947</time> William Shockley, John Bardeen and Walter Brattain of Bell Laboratories invent the transistor. They discovered how to make an electric switch with solid materials and no need for a vacuum.
</div>
</li>
<li>
<div>
<time>1953</time> Grace Hopper develops the first computer language, which eventually becomes known as COBOL. Thomas Johnson Watson Jr., son of IBM CEO Thomas Johnson Watson Sr., conceives the IBM 701 EDPM to help the United Nations keep tabs on Korea during the war.
</div>
</li>
</ul>
</section>

关于javascript - 为什么在我添加该功能时我的时间线没有消失又重新出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54119054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com