Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

div opacity / fade on .scrollTOp

I have one site with 9 sections and each of them has a div inside with the content.

I need that the opacity of this content reduces to 0 when the .scrollTop happens - so there is no conflict between the transparent nav and the text.

For now, in the code I'm using, the first text block performs the desired action, but the following text doesn't.

<!-- HTML -->

<div id="inicio" class="full first-section bgParallax" data-speed="0">
        <div class="content container div-content">
        <!-- Begin page content -->
        <div class="col-md-6 logo-bg">
            <h4 class="logotexto vermelho">NOME <strong> marca</strong>
            </h4>
        </div>
        <div>

            <div class="col-md-6 texto texto1">
                <?php the_field('texto1')?>
            </div>
      </div></div>
        <!-- CONTENT -->
    </div>
    <!-- First Section -->

jQuery(window).ready(function( $ ) {

$(".texto1").scroll(function(){
    $("texto1").css("opacity", 1 - $(".texto1").scrollTop() / 200);

  })

$(".texto2").scroll(function(){
    $("texto2").css("opacity", 1 - $(".texto1").scrollTop() / 200);

  })

});