自定义按钮和元素

  抱歉,这篇文章有英文版

In PRO you can add custom elements to the players UI like text, icon or image (for example, a logo). Use Elements / Add element button and select the required format.

For the Text, you need to add some text, for the Image link to the file or the content itself like data:URI, for SVG choose an icon from the collection, or place a SVG code. You can also load the SVG code dynamically if you specify there a JS variable like var:xxx

Video version of this guide for custom caption, image and SVG

Action

For an element to perform an action, you must specify an Action ‒ URL, an API command, or a Javascript call. For example, open url:

//playerjs.com

↓ launch the player

api:play

↓ rewind for ten seconds

api:seek,-10

↓ call a function called MyFunction, passing it two arguments. 

js:MyFunction,x,y

↓ you can use placeholders {title}{time}{file}

js:MyFunction,{file},{time}

↓ directly call a JS action that has parentheses (for example, returning the browser tab back)

js:history.go(-1)

↓ triggering JS event

event:myEvent

You need to subscribe the container: document.getElementById("player").addEventListener("myEvent",onMyEvent);

Reverse action

For elements Text and SVG you can add reverse. Add reverse text or reverse SVG code with separator ///

You can also add reverse action

You can also choose the opposite action of the Play button from Pause to Stop (actual for broadcasts and radio)

If you give an identifier to your element in the settings, you can switch its state through the JS API. In the following example, the button with the heart identifier will switch to the opposite state after the player is initialized. This may come in handy if the button controls an external function via JS.

function PlayerjsEvents(x){
   if(x=="init"){
      player.api("button","toogle","id:heart");
   }
}

How to combine icon and text

You need to create an element of type SVG and specify its code, or select the desired icon in the library. Then you need to include a Tooltip, specify text and also enable the Show always option. With the help of margins and paddings you can place this text in the right place and stretch the background to the required length.


20.0.5
2024 © PlayerJS

登录

登录

免费注册

注册
注册即表示您同意服务条款
登录(如果您有帐户)

恢复密码

恢复
忘记电子邮件?联系我们