Skip to Content

pauseAllVideos()

Pause all videos on the page.

JavaScript July 2, 2019

Usage

JavaScript
nebula.pauseAllVideos(force)

Parameters

force
(Optional) (Boolean) Force all videos to pause no matter what.
Default: None

Parameter Notes

An iframe with the class ignore-visibility will allow that video to continue playing regardless of page visibility.

If force is true, all videos will pause regardless.

Request or provide clarification »

Additional Notes

Important note: This function can only pause videos that are “known” to Nebula- only Youtube and Vimeo videos that are connected into the Nebula players object.

Source File

Located in /assets/js/nebula.js on line 5033.

JavaScript
nebula.pauseAllVideos = function(force){
    if ( typeof nebula.videos === 'undefined' ){
        return false; //If videos don't exist, then no need to pause
    }

    if ( force === 'null' ){
        force = false;
    }

    jQuery.each(nebula.videos, function(){
        if ( this.platform === 'html5' ){
            if ( (force || !jQuery(this.element).hasClass('ignore-visibility')) ){
                jQuery(this.element)[0].pause(); //Pause HTML5 Videos
            }
        }

        if ( this.platform === 'youtube' ){
            if ( (force || !jQuery(this.element).hasClass('ignore-visibility')) ){
                this.player.pauseVideo(); //Pause Youtube Videos
            }
        }

        if ( this.platform === 'vimeo' ){
            if ( (force || !jQuery(this.element).hasClass('ignore-visibility')) ){
                this.player.pause(); //Pause Vimeo Videos
            }
        }
    });
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.pauseAllVideos = function(force){
    //Write your own code here, leave it blank, or return false.
}