I tried to add two of my js animation into a one js file which is the timeline and the playlist animation. However, when i try to link the js file to mu html file, it didnt work. Only works if i put the script tag at the bottom of my body tag but online the playlist animation that is working but not the timeline animation. I cant figure out as to why this problem happened. I am still new to js hence thats why i encounter this problem. I thank those who take their time to figure this problem with me.
My index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style/main.css" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<!--Font-->
<link
href="https://fonts.googleapis.com/css2?family=Josefin+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&display=swap"
rel="stylesheet" />
<!--Social Media icons-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<title>Vague Models</title>
</head>
<body>
<header>
<div class="tophead">
<p>sushi tight, sushi clean, sushi fresh</p>
</div>
</header>
<div class="coverpage">
<nav class="menu">
<label><a href="index.html">Vague</a></label>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">Services</a>
<ul class="dropdown">
<li><a href="service1.html">Runway</a></li>
<li><a href="service2.html">Commercial</a></li>
<li><a href="service3.html">Fitness</a></li>
<li><a href="service4.html">Fashion</a></li>
</ul>
</li>
<li><a href="enquiry.html">Enquiry</a></li>
<li><a href="about.html">About</a></li>
<li><a href="disclaimer.html">Disclaimer</a></li>
<li><a href="enchancement.html">Enchancement</a></li>
<li><a href="acknowledgement.html">Acknowledgement</a></li>
</ul>
</nav>
<h1 class="title">Vague</h1>
</div>
<!--about-->
<section class="about">
<div class="main">
<img src="style/images/1.jpg" alt="model group photo" />
<div class="about-text">
<h2>Our Story</h2>
<h5>Director <span>& Models</span></h5>
<p>"He Who Must Not Be Named" as the company's creator, established Vague in 2020. Vague gave rise to
the Supermodel, which
has defined the business. By building the careers of our artists holistically and defining trends
within the industry,
Vague maintains its position as a leader in fashion. Vague has worked with artists, including Dante
and Nik Connor.
Vague's commitment to supporting diversity and developing our skills is advancing inclusion in the
sector. Vague
currently has offices in New York. Vague invites you to join us in defining what lies ahead as we
embark on a new
chapter in our illustrious history.</p>
<p>
<a class="button" href="enquiry.html">Let's Talk</a>
</p>
</div>
</div>
</section>
<div class="service">
<div class="title">
<h2>Our Services</h2>
</div>
<div class="box">
<div class="card">
<img src="images/spotlights.png" alt="spotlight2" />
<h5>Runway</h5>
<div class="pra">
<p>We believe modelling is a power for those who dare to show off attidude and confidents! Come and
check out our runway models
</p>
<p>
<a class="button" href="service1.html">Read Me</a>
</p>
</div>
</div>
<div class="card">
<img src="images/spotlight2.png" alt="spotlight2" />
<h5>Commercial</h5>
<div class="pra">
<p>We believe modelling is a power for those who dare to show off attidude and confidents! Come and
check out our Commercial models</p>
<p>
<a class="button" href="service2.html">Read Me</a>
</p>
</div>
</div>
<div class="card">
<img src="images/30_dumbell.png" alt="spotlight2" />
<h5>Fitness</h5>
<div class="pra">
<p>We believe modelling is a power for those who dare to show off attidude and confidents! Come and
check out our fitness models</p>
<p>
<a class="button" href="service3.html">Read Me</a>
</p>
</div>
</div>
<div class="card">
<img src="images/glasses_11.png" alt="spotlight2" />
<h5>Fashion</h5>
<div class="pra">
<p>We believe modelling is a power for those who dare to show off attidude and confidents! Come and
check out our fashion models</p>
<p>
<a class="button" href="service4.html">Read me</a>
</p>
</div>
</div>
</div>
</div>
<!--timeline-->
<div class="t-ctn">
<div class="t-sect">
<h1>Animated TimeLine</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat incidunt distinctio,
</p>
</div>
<div class="tl">
<div class="l"></div>
<div class="sect">
<div class="bead"></div>
<div class="content">
<h2>Web Development</h2>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Animi ab repellendus pariatur? Maxime eius excepturi
soluta doloremque, rerum vitae
similique cumque, numquam voluptatibus exercitationem
</p>
</div>
</div>
<div class="sect">
<div class="bead"></div>
<div class="content">
<h2>Web Development</h2>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Animi ab repellendus pariatur? Maxime eius excepturi
soluta doloremque, rerum vitae
</p>
</div>
</div>
<div class="sect">
<div class="bead"></div>
<div class="content">
<h2>Web Development</h2>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Animi ab repellendus pariatur? Maxime eius excepturi
soluta doloremque, rerum vitae
similique cumque, numquam voluptatibus exercitationem
</p>
</div>
</div>
</div>
<!--<div class="timeline">
<div class="box left">
<div class="text">
<h2>Vague Inc.</h2>
<small>2021 - 2022</small>
<p>Our models became among the top demanded models by many prestigious companies like Vilan,
Victorious Truth, Port, etc.</p>
<p>Dante C. (Vague Models) has won The World Mediocre Facade Man 2021. Apart from that, he has
brought the fame and honours
to our company.</p>
<span class="left-arrow"></span>
</div>
</div>
<div class="box right">
<div class="text">
<h2>Vague Inc.</h2>
<small>2021 - 2022</small>
<p>We managed to donate $ 4 million to the Stop White Bleaching Product campaign to spread awareness
of the adverse effects
of the skin bleaching product.</p>
<p>Organise the largest modelling auditions in world. The auditions covered countries like China,
India, US, UK, UAE, Korea, Japan, Malaysia, Indonesia, and Australia</p>
<p>Won The Best Modelling Company Mediocre Category by Guinness World Book of Record</p>
<span class="right-arrow"></span>
</div>
</div>
<div class="box left">
<div class="text">
<h2>Vague Inc.</h2>
<small>2021 - 2022</small>
<p>Managed to recruited 16 Best Models from countries around the world such as Malaysia, UK, US,
Ghana, India, Indonesia</p>
<p>Jessica W.(Vague Models) was voted for Social Stopper of the year 2022. She also seen on the
nominations list under the Breakdown Moon category.</p>
<span class="left-arrow"></span>
</div>
</div>
</div>-->
</div>
<!--Video of Models-->
<div class="models-ctn">
<h1>Check out our models!</h1>
<div class="v-ctn">
<section class="m-v">
<video src="video/mixkit-man-modelling-in-different-places-359.mp4" controls autoplay muted></video>
<h3 class="t">Title of the playing Video.</h3>
</section>
<section class="v-p">
<h3 class="t">Vague Models</h3>
<p>3 videos . .44s</p>
<div class="v">
</div>
</section>
</div>
<!--<div class="m-row">
<div class="m-col">
<div class="m-img">
<video controls autoplay>
<source src="video/mixkit-man-modelling-in-different-places-359.mp4" type="video/mp4" />
</video>
</div>
</div>
<div class="m-col">
<div class="m-img">
<video controls autoplay>
<source src="video/mixkit-two-elegant-women-taking-a-selfie-in-a-bathroom-43569.mp4"
type="video/mp4" />
</video>
</div>
</div>
<div class="m-col">
<div class="m-img">
<video controls autoplay>
<source src="video/mixkit-urban-fashion-female-models-43276.mp4" type="video/mp4" />
</video>
</div>
</div>
</div>-->
</div>
<!--Model cards-->
<div class="mod-ctn">
<h1>Our Top Models</h1>
<div class="mcard">
<div class="inner-card">
<div class="front">
<img src="images/s1m1.jpg" alt="model picture" />
</div>
<div class="back">
<h2>Awards:</h2>
<p>Biggest models ever awards</p>
<p>
<a class="button" href="service1.html">Read Me</a>
</p>
</div>
</div>
</div>
<div class="mcard">
<div class="inner-card">
<div class="front">
<img src="images/s1f1.jpg" alt="model picture" />
</div>
<div class="back">
<h2>Awards:</h2>
<p>Biggest models ever awards</p>
<p>
<a class="button" href="service1.html">Read Me</a>
</p>
</div>
</div>
</div>
<div class="mcard">
<div class="inner-card">
<div class="front">
<img src="images/s1f1d.jpg" alt="model picture" />
</div>
<div class="back">
<h2>Awards:</h2>
<p>Biggest models ever awards</p>
<p>
<a class="button" href="service1.html">Read Me</a>
</p>
</div>
</div>
</div>
<div class="mcard">
<div class="inner-card">
<div class="front">
<img src="images/s1m1d.jpg" alt="model picture" />
</div>
<div class="back">
<h2>Awards:</h2>
<p>Biggest models ever awards</p>
<p>
<a class="button" href="service1.html">Read Me</a>
</p>
</div>
</div>
</div>
</div>
<!--Google Map-->
<div class="g-ctn">
<h1>Our Office</h1>
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d387193.30594994064!2d-74.25986652425023!3d40.69714941680757!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89c24fa5d33f083b%3A0xc80b8f06e177fe62!2sNew%20York%2C%20NY%2C%20USA!5e0!3m2!1sen!2sid!4v1665210935288!5m2!1sen!2sid"
width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy"
referrerpolicy="no-referrer-when-downgrade"></iframe>
</div>
<!--Footer-->
<footer>
<p>Vague</p>
<p>For more information on our models - please click on the link below to subscribe to our channel:</p>
<div class="social">
<a href="https://www.youtube.com/"><i class="fab fa-youtube"></i></a>
<a href="https://www.instagram.com/"><i class="fab fa-instagram"></i></a>
<a href="https://twitter.com/"><i class="fab fa-twitter"></i></a>
</div>
<p class="end">CopyRight by Vague Inc.</p>
</footer>
<script src="javascripts/scriptb.js"></script>
</body>
</html>
My js file
/* timeline */
function qs(selector, all = false) {
return all ? document.querySelectorAll(selector) : document.querySelector(selector)
}
const sections = qs('.sect', true);
const timeline = qs('.tl');
const line = qs('.l');
line.style.bottom = `calc(100% - 20px)`;
let prevScrollY = window.scrollY;
let up, down;
let full = false;
let set = 0;
const targetY = window.innerHeight * 0.8;
function scrollHandler(e) {
const {
scrollY
} = window;
up = scrollY < prevScrollY;
down = !up;
const timelineRect = timeline.getBoundingClientRect();
const lineRect = line.getBoundingClientRect(); //CONST LINEHEIGHT = lineRect.bottom - lineRect.top
const dist = targetY - timelineRect.top
console.log(dist);
if (down && !full) {
set = Math.max(set, dist);
line.style.bottom = `calc(100% - ${set}px)`
}
if (dist > timeline.offsetHeight + 50 && !full) {
full = true;
line.style.bottom = `-50px`
}
sections.forEach(item => {
//console.log(items);
const rect = item.getBoundingClientRect();
if (rect.top + item.offsetHeight / 5 < targetY) {
item.classList.add('show-me')
}
});
prevScrollY = window.scrollY;
}
scrollHandler();
line.style.display = 'block';
window.addEventListener('scroll', scrollHandler)
/* video */
const main_video = document.querySelector('.m-v video');
const main_video_title = document.querySelector('.m-v .t');
const video_playlist = document.querySelector('.v-p .v');
let data = [
{
'id': 'a1',
'title': 'Max raider ',
'name': 'mixkit-man-modelling-in-different-places-359.mp4',
'duration': '0:21',
},
{
'id': 'a2',
'title': 'Tes and La',
'name': 'mixkit-two-elegant-women-taking-a-selfie-in-a-bathroom-43569.mp4',
'duration': '0:15',
},
{
'id': 'a3',
'title': 'Fac and Boo',
'name': 'mixkit-urban-fashion-female-models-43276.mp4',
'duration': '0:8',
},
];
data.forEach((video, i) => {
let video_element = `
<div class="video" data-id="${video.id}">
<img src="images/play.svg" alt="">
<p>${i + 1 > 9 ? i + 1 : '0' + (i + 1)}. </p>
<h3 class="title">${video.title}</h3>
<p class="time">${video.duration}</p>
</div>
`;
video_playlist.innerHTML += video_element;
})
let videos = document.querySelectorAll('.video');
videos[0].classList.add('active');
videos[0].querySelector('img').src = '../images/pause.svg';
videos.forEach(selected_video => {
selected_video.onclick = () => {
for (all_videos of videos) {
all_videos.classList.remove('active');
all_videos.querySelector('img').src = '../images/play.svg';
}
selected_video.classList.add('active');
selected_video.querySelector('img').src = '../images/pause.svg';
let match_video = data.find(video => video.id == selected_video.dataset.id);
main_video.src = 'video/' + match_video.name;
main_video_title.innerHTML = match_video.title;
}
});