Relax and Release Stress

by MD Hasan Patwary

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Release Stress</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="background-carousel" id="background-carousel">
        <!-- Images will be dynamically loaded here -->
    </div>
    <div class="content">
        <header>
            <h1>Relax and Release Stress</h1>
        </header>
        <section class="quote">
            <h2>Quote of the Day</h2>
            <p id="daily-quote">Loading quote...</p>
        </section>
        <section class="audio">
            <h2>Relaxing Music</h2>
            <audio controls>
                <source src="https://www.bensound.com/bensound-music/bensound-slowmotion.mp3" type="audio/mpeg">
                Your browser does not support the audio element.
            </audio>
        </section>
        <section class="breathing-exercise">
            <h2>Follow the Breathing Exercise</h2>
            <div class="circle"></div>
        </section>
        <button id="toggle-breathing">Toggle Breathing Animation</button>
    </div>
    <script src="script.js"></script>
</body>
</html>

CSS

/* Reset some default browser styles */
body, h1, h2, p {
    margin: 0;
    padding: 0;
    font-family: 'Arial', sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.background-carousel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.carousel-image {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 2s ease;
}

.carousel-image.active {
    opacity: 1;
}

.content {
    text-align: center;
    color: #fff;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    background: linear-gradient(120deg, rgba(132, 250, 176, 0.2), rgba(143, 211, 244, 0.2));
    border-radius: 10px;
    z-index: 1;
    position: relative;
    transition: background 2s ease; /* Smooth transition for gradient changes */
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 20px;
}

.quote {
    margin-bottom: 20px;
}

.quote h2 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

.quote p {
    font-size: 1.2em;
}

.audio {
    margin-bottom: 20px;
}

.audio h2 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

.breathing-exercise {
    margin-top: 30px;
}

.breathing-exercise h2 {
    margin-bottom: 20px;
}

.circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(120deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.7));
    margin: 0 auto;
    animation: breathe 5s infinite;
}

@keyframes breathe {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.5);
    }
    100% {
        transform: scale(1);
    }
}

button {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 1em;
    color: #333;
    background-color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s...

JavaScript

// script.js
document.addEventListener('DOMContentLoaded', function() {
    const circle = document.querySelector('.circle');
    const toggleButton = document.getElementById('toggle-breathing');
    const carouselContainer = document.getElementById('background-carousel');
    const quoteElement = document.getElementById('daily-quote');
    const contentElement = document.querySelector('.content');
    let currentIndex = 0;

    toggleButton.addEventListener('click', function() {
        if (circle.style.animationPlayState === 'paused') {
            circle.style.animationPlayState = 'running';
            toggleButton.textContent = 'Pause Breathing Animation';
        } else {
            circle.style.animationPlayState = 'paused';
            toggleButton.textContent = 'Resume Breathing Animation';
        }
    });

    // Start with animation running
    circle.style.animationPlayState = 'running';

    // Fetch images from Pexels API
    const apiKey = 'yEkMES04UOy5QapvbtdPh8NpFSixajwoQs2AL6DlDxUBqCd6Pmt7gJBx';
    const query = 'nature'; // You can change the query to fetch different images

    fetch(`https://api.pexels.com/v1/search?query=${query}&per_page=5`, {
        headers: {
            Authorization: apiKey
        }
    })
    .then(response => response.json())
    .then(data => {
        const photos = data.photos;
        const images = photos.map(photo => photo.src.large2x);
        loadImages(images);
        startCarousel(images);
    })
    .catch(error => console.error('Error fetching images:', error));

    // Fetch quotes from ZenQuotes API
    fetch('https://zenquotes.io/api/quotes')
    .then(response => response.json())
    .then(data => {
        const quotes = data.map(quote => `${quote.q} - ${quote.a}`);
        updateQuotes(quotes);
    })
    .catch(error => console.error('Error fetching quotes:', error));

    function loadImages(images) {
        images.forEach((src, index) => {
            const img =...