• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Jak naprawić tło pod stopką mające nieskończoną długość, przy zachowaniu efektu scrollowania parallax?

42 Warsaw Coding Academy
+1 głos
721 wizyt
pytanie zadane 25 maja 2021 w HTML i CSS przez pytanko Nowicjusz (130 p.)
edycja 25 maja 2021 przez ScriptyChris
Witam,

Zaczynam swoją przygodę ze stronami i mam problem. Kilka dni temu zacząłem pisać swoją stronę, jest ona prawie gotowa, lecz jest jeden problem, a mianowicie pod stopką automatycznie generuje się tło strony i może się ono ciągnąć w nieskończoność, chciałem się zapytać czy da się jakoś to naprawić, ustawić od górnie rozmiar strony, bądź coś takiego by zostały zachowane animacje Parallax Scrolling Effectu.

Z góry dziękuję za pomoc!
komentarz 25 maja 2021 przez niezalogowany

dołącz kod proszę wink

komentarz 25 maja 2021 przez pytanko Nowicjusz (130 p.)
<!DOCTYPE html>
<html>
    <head>
        <title> tytul | tytul</title>
        <link rel="stylesheet" type="text/css" href="style.css"
    </head>
    <body>
        <header>
            <a href="#" class="logo">nazwa</a>
            <ul>
                <li><a href="Strona główna/index.html">Strona główna</a></li>
                <li><a href="Regulamin/index.html">Regulamin</a></li>
                <li><a href="#">Kontakt</a></li>
            </ul>
        </header>
        <section>
            <img src="stars.png" id="stars">
            <img src="teamspeak.png" id="teamspeak">
            <img src="mountains_behind.png" id="mountains_behind">
            <h2 id="text">nazwa</h2>
            <a href="#sec" id="btn">O projekcie</a>
            <img src="mountains_front.png" id="mountains_front">
        </section>
        <div class="sec" id="sec">
            <h2>O projekcie</h2>
            <p> text
                <br><br>
                text
            </p>
        </div>
        <div class="footer">
            <div>!</div>

        <script>
            let stars = document.getElementById('stars');
            let teamspeak = document.getElementById('teamspeak');
            let mountains_behind = document.getElementById('mountains_behind');
            let text = document.getElementById('text');
            let btn = document.getElementById('btn');
            let mountains_front = document.getElementById('mountains_front');
            let header = document.querySelector('header');

            window.addEventListener('scroll', function(){
                let value = window.scrollY;
                stars.style.left = value * 0.25 + 'px';
                teamspeak.style.top = value * 1.05 + 'px';
                mountains_behind.style.top = value * 0.5 + 'px';
                mountains_front.style.top = value * 0 + 'px';
                text.style.marginRight = value * 4 + 'px';
                text.style.marginTop = value * 1.5 + 'px';
                header.style.top = value * 0.5 + 'px';
                

            })
        </script>
       

    </body>

</html>
@import url('https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900&display=swap');
*
{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    scroll-behavior: smooth;
}
body
{
    min-height: 100vh;
    overflow-x: hidden;
    background: linear-gradient(#2b1055,#7597de);
    

}
header
{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 30px 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10000;
    
    
}
header .logo
{
    color: #ffff;
    font-weight: 700;
    text-decoration: none;
    font-size: 2em;
    text-transform: uppercase;
    letter-spacing: 2px;
}
header ul
{
    display: flex;
    justify-content: center;
    align-items: center;
}
header ul li
{
    list-style: none;
    margin-left: 20px;
}
header ul li a
{
    text-decoration: none;
    padding: 6px 15px;
    color: #ffff;
    border-radius: 20px;
}
header ul li a:hover,
header ul li a.active
{
    background: #ffff;
    color: #2b1055;
}
section
{
    position: relative;
    width: 100%;
    height: 100vh;
    padding: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}
section::before
{
    content: '';
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100px;
    background: linear-gradient(to top,#1c0522,transparent);
    z-index: 1000;
}
section img
{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}
section img#teamspeak
{
    mix-blend-mode: screen;
}
section img#mountains_front
{
    z-index: 10;
}
#text
{
    position: absolute;
    color: #fff;
    white-space: nowrap;
    font-size: 4.5vw;
    z-index: 9;
}
#btn
{
    text-decoration: none;
    display: inline-block;
    padding: 8px 30px;
    border-radius: 40px;
    background: #fff;
    color: #2b1055;
    font-size: 1.5em;
    z-index: 9;
    transform: translateY(100px);
}
.sec
{
    position: relative;
    padding: 100px;
    background: #1c0522;
}
.sec h2
{
    font-size: 3.5em;
    margin-bottom: 10px;
    color: #fff;
}
.sec p
{
    font-size: 2em;
    color: #fff;
}

Czy teraz jest okej? (pierwszy raz korzystam z forum i tak średnio wiem co i jak)

komentarz 25 maja 2021 przez niezalogowany
tak.

rozwiązanie masz na samym dole.

2 odpowiedzi

0 głosów
odpowiedź 25 maja 2021 przez niezalogowany
<!DOCTYPE html>
<html>
    <head>
        <title> tytul | tytul</title>
        <link rel="stylesheet" type="text/css" href="style.css"
    </head>
    <body>
        <header>
            <a href="#" class="logo">nazwa</a>
            <ul>
                <li><a href="Strona główna/index.html">Strona główna</a></li>
                <li><a href="Regulamin/index.html">Regulamin</a></li>
                <li><a href="#">Kontakt</a></li>
            </ul>
        </header>
        <section>
            <img src="stars.png" id="stars">
            <img src="teamspeak.png" id="teamspeak">
            <img src="mountains_behind.png" id="mountains_behind">
            <h2 id="text">nazwa</h2>
            <a href="#sec" id="btn">O projekcie</a>
            <img src="mountains_front.png" id="mountains_front">
        </section>
        <div class="sec" id="sec">
            <h2>O projekcie</h2>
            <p> text
                <br><br>
                text
            </p>
        </div>
        <div class="footer">
            <div>!</div>

        <script>
//             let stars = document.getElementById('stars');
//             let teamspeak = document.getElementById('teamspeak');
//             let mountains_behind = document.getElementById('mountains_behind');
//             let text = document.getElementById('text');
//             let btn = document.getElementById('btn');
//             let mountains_front = document.getElementById('mountains_front');
//             let header = document.querySelector('header');

//             window.addEventListener('scroll', function(){
//                 let value = window.scrollY;
//                 stars.style.left = value * 0.25 + 'px';
//                 teamspeak.style.top = value * 1.05 + 'px';
//                 mountains_behind.style.top = value * 0.5 + 'px';
//                 mountains_front.style.top = value * 0 + 'px';
//                 text.style.marginRight = value * 4 + 'px';
//                 text.style.marginTop = value * 1.5 + 'px';
//                 header.style.top = value * 0.5 + 'px';
                

//             })
        </script>
       

    </body>

</html>
@import url('https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900&display=swap');



{

    margin: 0;

    padding: 0;

    box-sizing: border-box;

    font-family: 'Poppins', sans-serif;

    scroll-behavior: smooth;

}

body

{

    min-height: 100vh;

    overflow-x: hidden;

    background: linear-gradient(#2b1055,#7597de);

    

 

}

header

{

    position: absolute;

    top: 0;

    left: 0;

    width: 100%;

    padding: 30px 100px;

    display: flex;

    justify-content: space-between;

    align-items: center;

    z-index: 10000;

    

    

}

header .logo

{

    color: #ffff;

    font-weight: 700;

    text-decoration: none;

    font-size: 2em;

    text-transform: uppercase;

    letter-spacing: 2px;

}

header ul

{

    display: flex;

    justify-content: center;

    align-items: center;

}

header ul li

{

    list-style: none;

    margin-left: 20px;

}

header ul li a

{

    text-decoration: none;

    padding: 6px 15px;

    color: #ffff;

    border-radius: 20px;

}

header ul li a:hover,

header ul li a.active

{

    background: #ffff;

    color: #2b1055;

}

section

{

    position: relative;

    width: 100%;

    height: 100vh;

    padding: 100px;

    display: flex;

    justify-content: center;

    align-items: center;

}

section::before

{

    content: '';

    position: absolute;

    bottom: 0;

    width: 100%;

    height: 100px;

    background: linear-gradient(to top,#1c0522,transparent);

    z-index: 1000;

}

section img

{

    position: absolute;

    top: 0;

    left: 0;

    width: 100%;

    height: 100%;

    object-fit: cover;

    pointer-events: none;

}

section img#teamspeak

{

    mix-blend-mode: screen;

}

section img#mountains_front

{

    z-index: 10;

}

#text

{

    position: absolute;

    color: #fff;

    white-space: nowrap;

    font-size: 4.5vw;

    z-index: 9;

}

#btn

{

    text-decoration: none;

    display: inline-block;

    padding: 8px 30px;

    border-radius: 40px;

    background: #fff;

    color: #2b1055;

    font-size: 1.5em;

    z-index: 9;

    transform: translateY(100px);

}

.sec

{

    position: relative;

    padding: 100px;

    background: #1c0522;

}

.sec h2

{

    font-size: 3.5em;

    margin-bottom: 10px;

    color: #fff;

}

.sec p

{

    font-size: 2em;

    color: #fff;

}

 

0 głosów
odpowiedź 26 maja 2021 przez VBService Ekspert (256,600 p.)

Możesz ustanowić jakąś maksymalną wartość, do której ma działać skrolowanie, np.:

const max_height = window.innerHeight;

 

let stars = document.getElementById('stars');
let teamspeak = document.getElementById('teamspeak');
let mountains_behind = document.getElementById('mountains_behind');
let text = document.getElementById('text');
let btn = document.getElementById('btn');
let mountains_front = document.getElementById('mountains_front');
let header = document.querySelector('header');
const max_height = window.innerHeight;

window.addEventListener('scroll', function(){
  let value = window.scrollY; 
  if (max_height > value) {
    stars.style.left = value * 0.25 + 'px';
    teamspeak.style.top = value * 1.05 + 'px';
    mountains_behind.style.top = value * 0.5 + 'px';
    mountains_front.style.top = value * 0 + 'px';
    text.style.marginRight = value * 4 + 'px';
    text.style.marginTop = value * 1.5 + 'px';
    header.style.top = value * 0.5 + 'px';
  }
})

 

Podobne pytania

+1 głos
2 odpowiedzi 176 wizyt
pytanie zadane 5 lutego 2022 w HTML i CSS przez CYG4N Nowicjusz (240 p.)
0 głosów
1 odpowiedź 182 wizyt
pytanie zadane 8 lutego 2017 w HTML i CSS przez Bakr Mądrala (6,850 p.)
0 głosów
1 odpowiedź 124 wizyt
pytanie zadane 6 stycznia 2017 w JavaScript przez Bakr Mądrala (6,850 p.)

93,395 zapytań

142,388 odpowiedzi

322,566 komentarzy

62,753 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

VMware Cloud PRO - przenieś swoją infrastrukturę IT do chmury
...