0

I know this has been discussed before, but I can't seem to get it work for me, I would appreciate some help.

I'm trying to change the opacity of a logo after scrolling some pixels with this code:

<script>
        $(window).scroll(function() {
            if ( $(window).scrollTop() >= 675 ) {
                $('.logo_full').css('opacity', '1');
            } else {
                $('.logo_full').css('opacity', '0'); 
            }
        });
</script>

Here is a live version of the things. I believe it's better to check it out live rather than on some pieces of code. link

I'm starting to think that this is some js incompability or some stuff.

Any ideas?

2
  • There is no logo to change opacity on? this is why fiddle is better than full site... Commented Apr 17, 2015 at 22:22
  • There is a logo that is currently hidden via CSS. Commented Apr 17, 2015 at 22:24

1 Answer 1

2

Try:

$(document).ready(function() {
    $('#wrapper').scroll(function() {
        if ( $('#wrapper').scrollTop() >= 675 ) {
            $('.logo_full').css('opacity', '1');
        } else {
            $('.logo_full').css('opacity', '0'); 
        }
    });
});

$(window).scrollTop() is constantly returning 0, while as you scroll, $('#wrapper').scrollTop() will indeed return the result you are expecting. You may need to wrap it in a $(document).ready to make sure you are binding at the right time.

Sign up to request clarification or add additional context in comments.

4 Comments

I did as you said and the logo is still not turning to opacity 1. I've already upload it, could you check it out?
You have $(window).scroll, try $('#wrapper').scroll
Glad it worked for you. If you wanted to get fancy, you can leverage jQuery's fadeIn and fadeOut as well. api.jquery.com/category/effects/fading
I believe a transition on the css would be much more simple. my opinion tho.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.