Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple Vue.js component for fullscreen

License

NotificationsYou must be signed in to change notification settings

mirari/vue-fullscreen

Repository files navigation

A simple Vue.js component for fullscreen, based onscreenfull.js

npm versionlanguage

npm versionlanguage

npm downloadlicense

Quick Example

Support

Supported browsers

Note: In order to use this package in Internet Explorer, you need a Promise polyfill.

Note: Safari is supported on desktop and iPad, but not on iPhone.

Note: Navigating to another page, changing tabs, or switching to another application using any application switcher (or Alt-Tab) will likewise exit full-screen mode.

Learn more

Migration from <= 2.3.5

Component

In general, you can simply switch the fullscreen state using two-way binding, so you don't have to call the component methods directly.

Thebackground prop are removed, you can set it directly on the component

Api

Thewrapper and options such asbackground associated with it are removed, which has limited use cases, is not very customizable, and you can simply implement it yourself.

The method names are changed as follows:

oldnew
enterrequest
supportisEnabled
getState()isFullscreen

Installation

Install from NPM

npm install vue-fullscreen@legacy

Usage

To usevue-fullscreen, simply import it, and callVue.use() to install.

The component, directive and api will be installed together in the global.

<template><div><!-- Component  --><fullscreenv-model="fullscreen">      content</fullscreen><buttontype="button"@click="toggle">Fullscreen</button><!-- Api  --><buttontype="button"@click="toggleApi">FullscreenApi</button><!-- Directive  --><buttontype="button"v-fullscreen>FullscreenDirective</button></div></template><script>importVueFullscreenfrom'vue-fullscreen'importVuefrom'vue'Vue.use(VueFullscreen)exportdefault{methods:{toggle(){this.fullscreen=!this.fullscreen},toggleApi(){this.$fullscreen.toggle()},},data(){return{fullscreen:false,}}}</script>

Caution: Because of the browser security function, you can only call these methods by a user gesture(click orkeypress).

Usage of api

In your vue component, You can usethis.$fullscreen to get the instance.

this.$fullscreen.toggle()

Or you can just import the api method and call it.

<template><div><divclass="fullscreen-wrapper">      Content</div><buttontype="button"@click="toggle">Fullscreen</button></div></template><script>import{apiasfullscreen}from'vue-fullscreen'exportdefault{methods:{asynctoggle(){awaitfullscreen.toggle(this.$el.querySelector('.fullscreen-wrapper'),{teleport:this.teleport,callback:(isFullscreen)=>{//this.fullscreen = isFullscreen},})this.fullscreen=fullscreen.isFullscreen},},data(){return{fullscreen:false,teleport:true,}}}</script>

Methods & Attributes

toggle([target, options, force])

Toggle the fullscreen mode.

  • target:
    • Type:Element
    • Default:document.body
    • The element target for fullscreen.
  • options (optional):
    • Type:Object
    • The fullscreen options.
  • force (optional):
    • Type:Boolean
    • Default:undefined
    • passtrue to force enter ,false to exit fullscreen mode.

request([target, options])

enter the fullscreen mode.

  • target:
    • Type:Element
    • Default:document.body
    • The element target for fullscreen.
  • options (optional):
    • Type:Object
    • The fullscreen options.

exit()

exit the fullscreen mode.

Note: Each of these methods returns a promise object, and you can get the state after the promise has been resolved, or you can pass a callback function in options to get.

asynctoggle(){awaitthis.$fullscreen.toggle()this.fullscreen=this.$fullscreen.isFullscreen}

isFullscreen

get the fullscreen state.

  • Type:Boolean

Caution: The action is asynchronous, you can not get the expected state immediately following the calling method.

isEnabled

check browser support for the fullscreen API.

  • Type:Boolean

element

get the fullscreen element.

  • Type:Element | null

Options

callback

  • Type:Function
  • Default:null

It will be called when the fullscreen mode changed.

fullscreenClass

  • Type:String
  • Default:fullscreen

The class will be added to target element when fullscreen mode is on.

pageOnly

  • Type:Boolean
  • Default:false

Iftrue, only fill the page with current element.

Note: If the browser does not support full-screen Api, this option will be automatically enabled.

teleport

  • Type:Boolean
  • Default:true

Iftrue, the target element will be appended todocument.body when it is fullscreen.

This can avoid some pop-ups not being displayed.

Use as directive

You can usev-fullscreen to make any element have the effect of switching to full screen with a click.

<buttonv-fullscreen>FullScreen</button>

Or you can just import the directive and install it.

<template><div><divclass="fullscreen-wrapper">      Content</div><buttontype="button"v-fullscreen.teleport="options">Fullscreen</button></div></template><script>import{directiveasfullscreen}from'vue-fullscreen'exportdefault{directives:{    fullscreen},data(){return{options:{target:".fullscreen-wrapper",callback(isFullscreen){console.log(isFullscreen)},},}}}</script>

Modifiers

pageOnly

only fill the page with current element.

teleport

the component will be appended todocument.body when it is fullscreen.

This can avoid some pop-ups not being displayed.

Options

target

  • Type:String | Element
  • Default:document.body

The element can be specified using a style selector string, equivalent todocument.querySelector(target). Note that when passing an element object directly, you need to make sure that the element already exists. The internal elements of the current component may not be initialized when the directive is initialized.

callback

  • Type:Function
  • Default:null

It will be called when the fullscreen mode changed.

fullscreenClass

  • Type:String
  • Default:fullscreen

The class will be added to target element when fullscreen mode is on.

Use as component

You can simply import the component and register it locally.

<template><div><fullscreenv-model="fullscreen":teleport="teleport":page-only="pageOnly">      Content</fullscreen><buttontype="button"@click="toggle">Fullscreen</button></div></template><script>import{component}from'vue-fullscreen'exportdefault{components:{fullscreen:component,},methods:{toggle(){this.fullscreen=!this.fullscreen},},data(){return{fullscreen:false,teleport:true,pageOnly:false,}}}</script>

Props

fullscreen-class

  • Type:String
  • Default:fullscreen

The class will be added to the component when fullscreen mode is on.

exit-on-click-wrapper

  • Type:Boolean
  • Default:true

Iftrue, clicking wrapper will exit fullscreen.

page-only

  • Type:Boolean
  • Default:false

Iftrue, only fill the page with current element.

Note: If the browser does not support full-screen Api, this option will be automatically enabled.

teleport

  • Type:Boolean
  • Default:true

Iftrue, the component will be appended todocument.body when it is fullscreen.

This can avoid some pop-ups not being displayed.

Events

change

  • isFullscreen: The current fullscreen state.

This event fires when the fullscreen mode changed.

Plugin options

name

  • Type:String
  • Default:fullscreen

If you need to avoid name conflict, you can import it like this:

<template><div><!-- Component  --><fsv-model="fullscreen":teleport="teleport":page-only="pageOnly"@change="fullscreenChange">      content</fs><buttontype="button"@click="toggle">Fullscreen</button><!-- Api  --><buttontype="button"@click="toggleApi">FullscreenApi</button><!-- Directive  --><buttontype="button"v-fs.teleport>FullscreenDirective</button></div></template><script>importVueFullscreenfrom'vue-fullscreen'importVuefrom'vue'Vue.use(VueFullscreen,{name:'fs'})exportdefault{methods:{toggle(){this.fullscreen=!this.fullscreen},toggleApi(){this.$fs.toggle()},},data(){return{fullscreen:false,}}}</script>

About

A simple Vue.js component for fullscreen

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors8


[8]ページ先頭

©2009-2025 Movatter.jp