Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mdfaizaanalam committed Oct 4, 2024
1 parent 8e00a0a commit 840d730
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 197 deletions.
17 changes: 10 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@
<div class="nav__bar">
<div class="nav__header">
<div class="nav__logo">
<a href="#"><img src="assets/logo.png" alt="logo" /></a>
<a href="#header"><img src="assets/logo.png" alt="logo" /></a>
</div>
<div class="nav__menu__btn" id="menu-btn">
<i class="ri-menu-line"></i>
</div>
</div>
<ul class="nav__links" id="nav-links">
<li class="nav_style"><a href="#home">HOME</a></li>
<li class="nav_style"><a href="#about">ABOUT</a></li>
<li class="nav_style"><a href="#trainer">TRAINER</a></li>
<li class="nav_style"><a href="#client">CLIENT</a></li>
<li class="nav_style"><a href="#blog">BLOG</a></li>
<li class="nav_style"><a href="#contact">CONTACT</a></li>
<li><a href="#header" class="active">HOME</a></li>
<li><a href="#about">ABOUT</a></li>
<li><a href="#trainer">TRAINER</a></li>
<li><a href="#client">CLIENT</a></li>
<li><a href="#blog">BLOG</a></li>
<li><a href="#contact">CONTACT</a></li>
<i class="ri-close-line"></i>
</ul>
</div>
</nav>


<header class="header" id="header">
<div class="section__container header__container">
<div class="header__content">
Expand Down
248 changes: 131 additions & 117 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,144 +1,158 @@
// Existing Menu Button and ScrollReveal Logic
/*---------------------Slider-------------------------*/
const menuBtn = document.getElementById("menu-btn");
const navLinks = document.getElementById("nav-links");
const menuBtnIcon = menuBtn.querySelector("i");
const bmiBtn = document.getElementById("btn");
const closeIcon = navLinks.querySelector("i.ri-close-line");

menuBtn.addEventListener("click", (e) => {
navLinks.classList.toggle("open");

const isOpen = navLinks.classList.contains("open");
menuBtnIcon.setAttribute("class", isOpen ? "ri-close-line" : "ri-menu-line");
// Toggle the mobile menu visibility
menuBtn.addEventListener("click", () => {
navLinks.classList.add("open");
menuBtn.setAttribute("aria-expanded", "true"); // Accessibility
});

navLinks.addEventListener('click', (e) => {
navLinks.classList.remove('open');
menuBtnIcon.setAttribute('class', 'ri-menu-line');
});
// Close the menu when the close icon is clicked
if (closeIcon) {
closeIcon.addEventListener("click", () => {
navLinks.classList.remove("open");
menuBtn.setAttribute("aria-expanded", "false");
});
}

const scrollRevealOption = {
distance: '50px',
origin: 'bottom',
duration: 1000,
};

ScrollReveal().reveal(".header__content h1", {...scrollRevealOption});
ScrollReveal().reveal(".header__content h2", {...scrollRevealOption, delay: 500});
ScrollReveal().reveal(".header__content p", {...scrollRevealOption, delay: 1000});
ScrollReveal().reveal(".header__content .header__btn", {...scrollRevealOption, delay: 1500});
ScrollReveal().reveal(".about__card", {duration: 1000, interval: 500});
ScrollReveal().reveal(".trainer__card", {...scrollRevealOption, interval: 500});
ScrollReveal().reveal(".blog__card", {...scrollRevealOption, interval: 500});

const swiper = new Swiper(".swiper", {
loop: true,
pagination: {
el: ".swiper-pagination",
},
});
/*---------------------Navigation Active Link & Smooth Scroll-------------------------*/
function handleNavigationClick(event) {
// Prevent the default behavior of the anchor tag
event.preventDefault();

// Existing BMI Calculator Logic
bmiBtn.addEventListener("click", () => {
const height = parseInt(document.getElementById("height").value);
const weight = parseInt(document.getElementById("weight").value);
const result = document.getElementById("output");
let heightStatus = false, weightStatus = false;
// Remove the 'active' class from all navigation links
const links = document.querySelectorAll("nav ul li");
links.forEach((link) => link.classList.remove("active"));

if (height === '' || isNaN(height) || height <= 0) {
document.getElementById('height_error').innerHTML = 'Please provide a valid height';
} else {
document.getElementById('height_error').innerHTML = '';
heightStatus = true;
}
// Add the 'active' class to the clicked link's parent li element
event.target.parentNode.classList.add("active");

if (weight === '' || isNaN(weight) || weight <= 0) {
document.getElementById('weight_error').innerHTML = 'Please provide a valid weight';
} else {
document.getElementById('weight_error').innerHTML = '';
weightStatus = true;
}
// Smooth scroll to the target section
const targetId = event.target.getAttribute("href").substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
targetSection.scrollIntoView({ behavior: "smooth" });
}

if (heightStatus && weightStatus) {
const bmi = (weight / ((height * height) / 10000)).toFixed(2);
// Close the menu after clicking on a link (for mobile)
navLinks.classList.remove("open");
menuBtn.setAttribute("aria-expanded", "false");
}

const navLinksItems = document.querySelectorAll("nav ul li a");
navLinksItems.forEach((link) => {
link.addEventListener("click", handleNavigationClick);
});

if (bmi < 18.6) {
result.innerHTML = 'Underweight: ' + bmi;
} else if (bmi > 24.9) {
result.innerHTML = 'Overweight: ' + bmi;
} else {
result.innerHTML = 'Normal: ' + bmi;
}
// Existing BMI Calculator Logic
bmiBtn.addEventListener("click", () => {
const height = parseInt(document.getElementById("height").value);
const weight = parseInt(document.getElementById("weight").value);
const result = document.getElementById("output");
let heightStatus = false,
weightStatus = false;

if (height === "" || isNaN(height) || height <= 0) {
document.getElementById("height_error").innerHTML =
"Please provide a valid height";
} else {
document.getElementById("height_error").innerHTML = "";
heightStatus = true;
}

if (weight === "" || isNaN(weight) || weight <= 0) {
document.getElementById("weight_error").innerHTML =
"Please provide a valid weight";
} else {
document.getElementById("weight_error").innerHTML = "";
weightStatus = true;
}

if (heightStatus && weightStatus) {
const bmi = (weight / ((height * height) / 10000)).toFixed(2);

if (bmi < 18.6) {
result.innerHTML = "Underweight: " + bmi;
} else if (bmi > 24.9) {
result.innerHTML = "Overweight: " + bmi;
} else {
alert('The form has errors');
result.innerHTML = '';
result.innerHTML = "Normal: " + bmi;
}
} else {
alert("The form has errors");
result.innerHTML = "";
}
});

// Add Protein Intake Calculator Logic
document.getElementById("protein-btn").addEventListener("click", function() {
let weight = parseFloat(document.getElementById("protein-weight").value);
let goal = document.getElementById("protein-goal").value;
let proteinIntake;

// Protein intake values based on goals (in grams per kg)
if (goal === "maintenance") {
proteinIntake = weight * 1.2;
} else if (goal === "muscle-gain") {
proteinIntake = weight * 1.6;
} else if (goal === "fat-loss") {
proteinIntake = weight * 2.0;
}

document.getElementById("protein-output").innerHTML =
`You need approximately ${proteinIntake.toFixed(2)} grams of protein per day.`;
document.getElementById("protein-btn").addEventListener("click", function () {
let weight = parseFloat(document.getElementById("protein-weight").value);
let goal = document.getElementById("protein-goal").value;
let proteinIntake;

// Protein intake values based on goals (in grams per kg)
if (goal === "maintenance") {
proteinIntake = weight * 1.2;
} else if (goal === "muscle-gain") {
proteinIntake = weight * 1.6;
} else if (goal === "fat-loss") {
proteinIntake = weight * 2.0;
}

document.getElementById(
"protein-output"
).innerHTML = `You need approximately ${proteinIntake.toFixed(
2
)} grams of protein per day.`;
});

// Add Macronutrient Calculator Logic
document.getElementById("macro-btn").addEventListener("click", function() {
let weight = parseFloat(document.getElementById("macro-weight").value);
let goal = document.getElementById("macro-goal").value;
let calories = parseFloat(document.getElementById("macro-calories").value);

let proteinRatio, carbRatio, fatRatio;

// Macro ratios based on fitness goals
if (goal === "maintenance") {
proteinRatio = 0.3;
carbRatio = 0.4;
fatRatio = 0.3;
} else if (goal === "bulking") {
proteinRatio = 0.25;
carbRatio = 0.5;
fatRatio = 0.25;
} else if (goal === "cutting") {
proteinRatio = 0.35;
carbRatio = 0.3;
fatRatio = 0.35;
}

// Calculate macros in grams
let proteinGrams = (calories * proteinRatio) / 4;
let carbGrams = (calories * carbRatio) / 4;
let fatGrams = (calories * fatRatio) / 9;

document.getElementById("macro-output").innerHTML =
`Your daily macronutrient breakdown:
document.getElementById("macro-btn").addEventListener("click", function () {
let weight = parseFloat(document.getElementById("macro-weight").value);
let goal = document.getElementById("macro-goal").value;
let calories = parseFloat(document.getElementById("macro-calories").value);

let proteinRatio, carbRatio, fatRatio;

// Macro ratios based on fitness goals
if (goal === "maintenance") {
proteinRatio = 0.3;
carbRatio = 0.4;
fatRatio = 0.3;
} else if (goal === "bulking") {
proteinRatio = 0.25;
carbRatio = 0.5;
fatRatio = 0.25;
} else if (goal === "cutting") {
proteinRatio = 0.35;
carbRatio = 0.3;
fatRatio = 0.35;
}

// Calculate macros in grams
let proteinGrams = (calories * proteinRatio) / 4;
let carbGrams = (calories * carbRatio) / 4;
let fatGrams = (calories * fatRatio) / 9;

document.getElementById(
"macro-output"
).innerHTML = `Your daily macronutrient breakdown:
Protein: ${proteinGrams.toFixed(2)}g,
Carbs: ${carbGrams.toFixed(2)}g,
Fats: ${fatGrams.toFixed(2)}g.`;
});

// Send email logic
function sendEmail() {
Email.send({
Host: "smtp.gmail.com",
Username: "[email protected]",
Password: "Pallavi@2005??",
To: '[email protected]',
From: document.getElementById("email").value,
Subject: "This is the subject",
Body: "And this is the body"
}).then(
message => alert(message)
);
Email.send({
Host: "smtp.gmail.com",
Username: "[email protected]",
Password: "Pallavi@2005??",
To: "[email protected]",
From: document.getElementById("email").value,
Subject: "This is the subject",
Body: "And this is the body",
}).then((message) => alert(message));
}
Loading

0 comments on commit 840d730

Please sign in to comment.