0

I am using the following onclick function that triggers the object to become full screen when clicked. I want the object to be fullscreen when the page loads without having to click.

  fbNav.find('ul li.fullscreen').on('click', function(e){
        if(!fullscreen) {
            fbFullscreen.show();
            fbFullscreen.append(fbCont);

            $window.trigger('resize');
        } else {
            fbParent.append(fbCont);
            fbFullscreen.hide();

            $window.trigger('resize');
        }

        fullscreen = !fullscreen;
    });

How can i achieve this?

2 Answers 2

1

You better put the main logic in a function and call the same function on ready and click.

function fullscreen(){
    if(!fullscreen) {
        fbFullscreen.show();
        fbFullscreen.append(fbCont);

        $window.trigger('resize');
    } else {
        fbParent.append(fbCont);
        fbFullscreen.hide();

        $window.trigger('resize');
    }

    fullscreen = !fullscreen;
}

//will be executed when page loads
$(document).ready(function(){
    fullscreen();
});

//will be executed on click
fbNav.find('ul li.fullscreen').on('click', function(e){
    fullscreen();
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can trigger click event on page load.

fbNav.find('ul li.fullscreen').trigger("click");

Comments

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.