Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

In this post, I asked how to scroll to an element and hide another via jQuery.

In my main javascript file I've made a script, but I'm not sure if it's correct. Can you tell me if this is a good way to do it, or if I can do it another better way?

$(function() {
    //Some default variables?
    var headerLoaded = true,
            contentLoaded = false,
            header = "#fitScreen";
    exploreBtn = "#exploreBtn",
            content = "#content";

    //This starts up a fullscreen video
    var videobackground = new $.backgroundVideo($(header), {
        "path": "assets/video/",
        "filename": "oceans",
        "types": ["mp4", "ogg", "webm"]
    });

    //When i click on the button the actually load the content
    $(exploreBtn).on('click', function() {
        event.preventDefault();
        init();
    });

    var init = function() {
        if (!contentLoaded && headerLoaded) {
            console.log("Loading content....");
            $(content).fadeIn(500, function() {
                $('html body').animate({
                    scrollTop: $(content).offset().top
                }, 1000, function() {
                    $(header).fadeOut(100, function() {
                        headerLoaded = false;
                        $('#content').css('top', 0);
                        $('html, body').css('overflow-y', 'scroll');
                        $(window).scrollTop(0);
                        $('nav').navi();
                    });
                    contentLoaded = true;
                    console.log("Done");
                });
            });
        } else {
            alert('Content already loaded..');
            $(this).stop();
        }
    };
});
share|improve this question
    
Can you provide a jsfiddle for this one too? –  Larz Jul 2 '14 at 21:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.