CorvidReference

AudioPlayer

An element for playing audio files.

The Wix Audio Player allows you to add single audio tracks to your website.

For a list of audio file types and sizes supported by the Wix Audio Player, click here.

Table of Contents

PROPERTIES

?
Store values associated with an object.
artistNameSets or gets the name of the artist displayed in an audio player.
collapsedIndicates if the element is collapsed or expanded.
coverImageSets or gets the cover image displayed in an audio player.
currentTimeGets the current play time from the beginning of the audio track, in seconds.
durationGets the total play time of the audio track, in seconds.
globalIndicates if an element appears on all pages or only on the current page.
hiddenIndicates if the element is visible or hidden.
idGets the element's ID.
isMutedIndicates if the volume is currently muted.
isPlayingIndicates if an audio track is currently playing.
isVisibleIndicates if the element is actually visible.
parentGets the element's parent element.
renderedIndicates if an element is currently displayed.
srcSets or gets the file location of the audio file.
trackNameSets or gets the track name displayed in an audio player.
typeGets the element's type.
volumeSets or gets an audio player's volume.

FUNCTIONS

?
Perform actions on an object.
collapse( )Collapses the element and sets its collapsed property to true.
expand( )Expands the element and sets its collapsed property to false.
hide( )

Hides the element and sets its hidden property to true, using an effect if specified.

mute( )Mutes audio volume.
onEnded( )Adds an event handler that runs when playback has ended.
onMouseIn( )

Adds an event handler that runs when the mouse pointer is moved onto the element.

onMouseOut( )

Adds an event handler that runs when the mouse pointer is moved off of the element.

onPause( )Adds an event handler that runs when playback is paused.
onPlay( )Adds an event handler that runs when playback is started or restarted.
onProgress( )Adds an event handler that runs when playback progresses.
onViewportEnter( )

Adds an event handler that runs when an element is displayed in the viewable part of the current window.

onViewportLeave( )

Adds an event handler that runs when an element is no longer displayed in the viewable part of the current window.

pause( )Pauses playback.
play( )Begins or resumes playback.
scrollTo( )Scrolls the page to the element using an animation.
seek( )Moves playback to the specified time, in seconds.
show( )

Shows the element and sets its hidden property to false, using an effect if specified.

stop( )Stops playback.
togglePlay( )Toggles playback.
unmute( )Unmutes audio volume.

MIXES IN

?
Where some functionality is inherited from.
$w.Element, $w.HiddenCollapsedMixin

artistName

Sets or gets the name of the artist displayed in an audio player.

Syntax

get artistName(): string
set artistName(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get the audio player's artist name

let artist = $w("#myAudioPlayer").artistName // "Artist name"

Set the audio player's artist name

$w("#myAudioPlayer").artistName = "Artist name";

collapsed

Indicates if the element is collapsed or expanded.

Description

If collapsed is true, the element is not displayed on the page under any circumstances. A collapsed element, unlike a hidden element, does not take up any space on the page. When collapsed, elements positioned within 70 pixels below the collapsed element and each other move up to take the collapsed element's place where possible. The elements that move up maintain their positions relative to one another.

If collapsed is false, the element may be displayed on the page. Elements that moved up to take the collapsed element's place on the page are moved back down.

However, an expanded element (an element whose collapsed property is false) is still not displayed if:

Even if the element is not be displayed due to the conditions mentioned above, if its collapsed property is false, it's displayed when the conditions no longer apply.

To set the collapsed property on an element, use the element's collapse() and expand() functions.

If you select Collapsed on load in the element's Properties panel in the Editor, the collapsed property is set to true when the page loads.

See Also

collapse( ), expand( ), hide( ), show( ), hidden

Syntax

get collapsed(): boolean
TYPE
?
The kind of data the property stores.
boolean
DEFAULT VALUE
?
The value of a property before you explicitly set it.
false

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Get an element's collapsed status

let isCollapsed = $w("#myElement").collapsed; // false

Toggle an element's collapsed state

if( $w("#myElement").collapsed ) {
  $w("#myElement").expand();
}
else {
  $w("#myElement").collapse();
}

coverImage

Sets or gets the cover image displayed in an audio player.

Description

Setting the coverImage property changes the displayed image to the image found at the new coverImage value.

Getting the coverImage property returns the location of the cover image file.

The image file can either be from the Media Manager or an external file from any web location.

The following URL formats are supported:

  • Media Manager: wix:image://v1/<uri>/<filename>#originWidth=<width>&originHeight=<height>[&watermark=<watermark_manifest_string>]
  • Web URL: http(s)://<image url>

Syntax

get coverImage(): string
set coverImage(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get the cover image's location

let coverImageSource = $w("#myAudioPlayer").coverImage;
// "wix:image://v1/68d3...cad2.jpg/flowers.jpg#originWidth=1970&originHeight=112

Set the cover image to be an image from the Media Manager

$w("#myAudioPlayer").coverImage = "wix:image://v1/68d3...cad2.jpg/flowers.jpg#originWidth=1970&originHeight=1120";

Set the cover image to be an image from the web

$w("#myAudioPlayer").coverImage = "http://placehold.it/250x250";

currentTime

Gets the current play time from the beginning of the audio track, in seconds.

Description

To set the currentTime property, use the seek() function.

Syntax

get currentTime(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the current play time

let currentTime = $w("#myAudioPlayer").currentTime // 137

duration

Gets the total play time of the audio track, in seconds.

Syntax

get duration(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the current audio track's duration

let duration = $w("#myAudioPlayer").duration // 198

global

Indicates if an element appears on all pages or only on the current page.

Description

If global is true, the element appears on all pages.

If global is false, the element only appears on the current page.

Syntax

get global(): boolean
TYPE
?
The kind of data the property stores.
boolean
DEFAULT VALUE
?
The value of a property before you explicitly set it.
false

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get whether an element is displayed on all pages

let isGlobal = $w("#myElement").global; // false

hidden

Indicates if the element is visible or hidden.

Description

If hidden is true, the element is not displayed on the page under any circumstances. A hidden element, unlike a collapsed element, continues to take up the same space on the page as it did when it was visible.

If hidden is false, the element may be displayed on the page.

However, an element whose hidden property is false is still not displayed if:

Even if the element is not displayed due to the conditions mentioned above, if its hidden property is set to false, it's displayed when the conditions no longer apply.

To determine if the element is actually visible, use the isVisible property.

To set the hidden property on an element, use the element's hide() or show() functions.

If you select Hidden on load in the element's Properties panel in the Editor, the hidden property is set to true when the page loads.

Note

An element's hidden property is not the same as its isVisible property. The hidden property indicates whether the element should be displayed, while isVisible indicates if it is actually displayed.

See Also

hide( ), show( ), collapse( ), expand( ), collapsed, rendered

Syntax

get hidden(): boolean
TYPE
?
The kind of data the property stores.
boolean
DEFAULT VALUE
?
The value of a property before you explicitly set it.
false

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Get an element's hidden status

let isHidden = $w("#myElement").hidden;  // false

Toggle an element's hidden state

if( $w("#myElement").hidden ) {
  $w("#myElement").show();
}
else {
  $w("#myElement").hide();
}

id

Gets the element's ID.

Description

The ID is the element's unique identifier. It is used when selecting elements using the $w() function.

An element's id is set in the Editor using the Properties panel.

Syntax

get id(): string
TYPE
?
The kind of data the property stores.
string

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the ID

let myId = $w("#myElement").id; // "myElement"

isMuted

Indicates if the volume is currently muted.

Description

To set the isMuted property, use the mute() and unmute() functions.

Syntax

get isMuted(): boolean
TYPE
?
The kind of data the property stores.
boolean

Examples

Get whether the volume is muted

let isMuted = $w("#myAudioPlayer").isMuted // false

isPlaying

Indicates if an audio track is currently playing.

Description

To set the isPlaying property, use the play(), pause(), and stop() functions.

Syntax

get isPlaying(): boolean
TYPE
?
The kind of data the property stores.
boolean

Examples

Get whether an audio track is playing

let isPlaying = $w("#myAudioPlayer").isPlaying // true

isVisible

Indicates if the element is actually visible.

Description

If isVisible is true, the element is displayed on the page.

If isVisible is false, the element is not displayed on the page.

The value of the isVisible property is calculated based on the hidden, collapsed, and rendered properties of the element and all of its ancestors. It is true only if the conditions exist in the element's property values and the property values of its ancestors such that the element is actually displayed on the page.

Note

An element's isVisible property is not the same as its hidden property. The isVisible property indicates whether the element is actually displayed, while hidden indicates if it should be displayed.

The isVisible property of an element remains true even if another element completely covers it so that a user cannot see it.

See Also

hidden, collapsed, rendered

Syntax

get isVisible(): boolean
TYPE
?
The kind of data the property stores.
boolean
DEFAULT VALUE
?
The value of a property before you explicitly set it.
true

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Get whether an element is visible

let isVisible = $w("#myElement").isVisible;  // true

parent

Gets the element's parent element.

Description

Some elements can contain other elements. This occurs when you drag an element onto a container element. The container is the parent of all the elements it contains.

Page, Header, and Footer are top-level elements and have no parent.

See Also

children

Syntax

get parent(): Node
TYPE
?
The kind of data the property stores.
DEFAULT VALUE
?
The value of a property before you explicitly set it.
null

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the parent element and the parent's ID

let parentElement = $w("#myElement").parent;

let parentId = parentElement.id; // "page1"

rendered

Indicates if an element is currently displayed.

Description

If rendered is true, the element is in the current DOM structure and can be used.

If rendered is false the element is not in the current DOM structure.

An element might not be in the DOM if it is in a slide or a state which is not currently showing.

See Also

collapsed, hidden, isVisible

Syntax

get rendered(): boolean
TYPE
?
The kind of data the property stores.
boolean
DEFAULT VALUE
?
The value of a property before you explicitly set it.
false

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get an element's rendered status

let isRendered = $w("#myElement").rendered;  // true

src

Sets or gets the file location of the audio file.

Description

Setting the src property changes the audio file to the audio found at the new src value.

Getting the src property returns the location of the audio file.

The audio file can be either from the Media Manager or an external audio file from any web location.

The URL formats supported are:

  • Media Manager: wix:audio://v1/<audio_uri>/<filename>#duration=<duration>
  • Web URL: (http(s)|blob|data)://site.com/audio-file.mp3

Syntax

get src(): string
set src(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get the audio track's location

let audioSrc = $w("#myAudioPlayer").src;
// "wix:audio://v1/22cf...185.mp3/Star Spangled Banner on Electric Guitar.#duration=132"

Set the audio track to an audio file uploaded to your site

$w("#myAudioPlayer").src = "wix:audio://v1/22cf...185.mp3/Star Spangled Banner on Electric Guitar.#duration=132";

Set the audio track to an external audio URL

$w("#myAudioPlayer").src = "http://lcweb2.loc.gov/natlib/ihas/service/ssbanner/100010509/100010509.mp3";

trackName

Sets or gets the track name displayed in an audio player.

Syntax

get trackName(): string
set trackName(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get an audio player's track name

let track = $w("#myAudioPlayer").trackName // "Track name"

Set an audio player's track name

$w("#myAudioPlayer").trackName = "Track name";

type

Gets the element's type.

Syntax

get type(): string
TYPE
?
The kind of data the property stores.
string

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the element's type

let myType = $w("#myElement").type; // "$w.Type"

volume

Sets or gets an audio player's volume.

Description

Setting the volume property sets the audio player's percentage of total volume. Set the value to a number between 0 and 100.

Getting the volume property returns the audio player's current percentage of total volume.

Note

The actual volume heard by a site visitor depends on the value of the volume property and the volume settings on the visitor's device.

Syntax

get volume(): number
set volume(value: number): void
TYPE
?
The kind of data the property stores.
number

Examples

Get an audio player's volume

let volume = $w("#myAudioPlayer").volume // 42

Set an audio player's volume

$w("#myAudioPlayer").volume = 42;

collapse( )

Collapses the element and sets its collapsed property to true.

Description

The collapse() function returns a Promise that is resolved when the element's collapsed property has been set to true.

To learn about the behavior of a collapsed element, see the collapsed property.

You can also collapse an element when the page loads by using the Properties panel in the Editor.

See Also

expand( ), collapsed, hide( )

Syntax

function collapse(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the element's collapsed property has been set to true.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Collapse an element

$w("#myElement").collapse();

Collapse an element and log a message when done

$w("#myElement").collapse()
  .then( () => {
    console.log("Done with collapse");
  } );

Toggle an element's collapsed state

if( $w("#myElement").collapsed ) {
  $w("#myElement").expand();
}
else {
  $w("#myElement").collapse();
}

expand( )

Expands the element and sets its collapsed property to false.

Description

The expand() function returns a Promise that is resolved when the element's collapsed property has been set to false.

To learn about the behavior of an expanded element, see the collapsed property.

See Also

expand( ), collapsed, show( )

Syntax

function expand(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the element's collapsed property has been set to false.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Expand an element

$w("#myElement").expand();

Expand an element and log a message when done

$w("#myElement").expand()
  .then( () => {
    console.log("Done with expand");
  } );

Toggle an element's collapsed state

if( $w("#myElement").collapsed ) {
  $w("#myElement").expand();
}
else {
  $w("#myElement").collapse();
}

hide( )

Hides the element and sets its hidden property to true, using an effect if specified.

Description

The hide() function hides the element and returns a Promise that is resolved when the effect is complete and the element's hidden property has been set to true.

To learn about the behavior of a hidden element, see the hidden property.

You can optionally apply an effect when hiding the element by providing an effectName value. You can also customize the effect by providing the optional effectOptions object.

Effects:

You can also hide an element when the page loads by using the Properties panel in the Editor.

See Also

show( ), hidden, collapse( )

Syntax

function hide([effectName: string], [effectOptions: ArcEffectOptions | BounceEffectOptions | FadeEffectOptions | FlipEffectOptions | FloatEffectOptions | FlyEffectOptions | FoldEffectOptions | GlideEffectOptions | PuffEffectOptions | RollEffectOptions | SlideEffectOptions | SpinEffectOptions | TurnEffectOptions | ZoomEffectOptions]): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the effect is complete and the element's hidden property has been set to true.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Hide an element with no effect

$w("#myElement").hide();

Hide an element with the "fade" effect

$w("#myElement").hide("fade");

Hide an element with the "fade" effect and custom options

let fadeOptions = {
  "duration":   2000,
  "delay":      1000
};

$w("#myElement").hide("fade", fadeOptions);

Hide an element with an effect and log a message when the effect is done

$w("#myElement").hide("fade")
  .then( ( ) => {
    console.log("Done with fade");
} );

Toggle an element's hidden state

if( $w("#myElement").hidden ) {
  $w("#myElement").show();
}
else {
  $w("#myElement").hide();
}

mute( )

Mutes audio volume.

Syntax

function mute(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the volume has been muted.

Examples

Mute volume

$w("#myAudioPlayer").mute();

Mute volume and log a message when done

$w("#myAudioPlayer").mute()
  .then( () => {
    console.log("Done with mute");
  } );

onEnded( )

Adds an event handler that runs when playback has ended.

Description

An audio track ends when playback reaches the duration of the audio.

Syntax

function onEnded(handler: EventHandler): AudioPlayer
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the audio track has ended.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The audio player that triggered the event.

Examples

Get the ID of the audio player whose audio track has ended

$w("#myAudioPlayer").onEnded( (event) => {
  let targetId = event.target.id; // "myAudioPlayer"
});

onMouseIn( )

Adds an event handler that runs when the mouse pointer is moved onto the element.

Note

Deprecation note: The $w parameter of event handlers is being deprecated. To get a scoped selector for working with elements in repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context). To learn more, see here.

Syntax

function onMouseIn(handler: MouseEventHandler): Element
callback MouseEventHandler(event: MouseEvent, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: MouseEvent, $w: $w)

The name of the function or the function expression to run when the mouse pointer is moved onto the element.

?
Values that you pass to a function.
event
The mouse event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The element to which the event handler was added.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the mouse event info when the mouse enters an element

$w("#myElement").onMouseIn( (event) => {
  let clientX = event.clientX;  // 362
  let clientY = event.clientY;  // 244
  let offsetX = event.offsetX;  // 10
  let offsetY = event.offsetY;  // 12
  let pageX = event.pageX;      // 362
  let pageY = event.pageY;      // 376
  let screenX = event.screenX;  // 3897
  let screenY = event.screenY;  // 362
} );

onMouseOut( )

Adds an event handler that runs when the mouse pointer is moved off of the element.

Note

Deprecation note: The $w parameter of event handlers is being deprecated. To get a scoped selector for working with elements in repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context). To learn more, see here.

Syntax

function onMouseOut(handler: MouseEventHandler): Element
callback MouseEventHandler(event: MouseEvent, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: MouseEvent, $w: $w)

The name of the function or the function expression to run when the mouse pointer is moved off of the element.

?
Values that you pass to a function.
event
The mouse event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The element to which the event handler was added.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the mouse event info when the mouse exits an element

$w("#myElement").onMouseOut( (event) => {
  let clientX = event.clientX;  // 362
  let clientY = event.clientY;  // 244
  let offsetX = event.offsetX;  // 10
  let offsetY = event.offsetY;  // 12
  let pageX = event.pageX;      // 362
  let pageY = event.pageY;      // 376
  let screenX = event.screenX;  // 3897
  let screenY = event.screenY;  // 362
} );

onPause( )

Adds an event handler that runs when playback is paused.

Description

An audio track can be paused by a user clicking the audio player's pause button or by calling its pause() or stop() functions.

See Also

pause( )

Syntax

function onPause(handler: EventHandler): AudioPlayer
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the audio track is paused.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The audio player that triggered the event.

Examples

Get the ID of the audio player that has been paused

$w("#myAudioPlayer").onPause( (event) => {
  let targetId = event.target.id; // "myAudioPlayer"
});

onPlay( )

Adds an event handler that runs when playback is started or restarted.

Description

An audio track can be played by a user clicking the audio player's play button or by calling its play() function.

See Also

play( )

Syntax

function onPlay(handler: EventHandler): AudioPlayer
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the audio track is played.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The audio player that triggered the event.

Examples

Get the ID of the audio player that is playing

$w("#myAudioPlayer").onPlay( (event) => {
  let targetId = event.target.id; // "myAudioPlayer"
});

onProgress( )

Adds an event handler that runs when playback progresses.

Description

An audio track continually progresses as the audio plays.

Syntax

function onProgress(handler: EventHandler): AudioPlayer
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the audio track progresses.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The audio player that triggered the event.

Examples

Get the ID of the audio player whose audio track is progressing

$w("#myAudioPlayer").onProgress( (event) => {
  let targetId = event.target.id; // "myAudioPlayer"
});

onViewportEnter( )

Adds an event handler that runs when an element is displayed in the viewable part of the current window.

Description

An element enters the viewport when the page is scrolled to show any part of the element. An element also enters the viewport if it was hidden or collapsed and is then shown or expanded in the viewable part of the current window. onViewportEnter() is not fired for hidden or collapsed elements even if they are scrolled into view.

Note

Deprecation note: The $w parameter of event handlers is being deprecated. To get a scoped selector for working with elements in repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context). To learn more, see here.

See Also

onViewportLeave( )

Syntax

function onViewportEnter(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the element enters the viewport.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The element on which the event is now registered.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the ID of the element that has entered the viewport

$w("#myElement").onViewportEnter( (event) => {
  let targetId = event.target.id; // "myElement"
});

onViewportLeave( )

Adds an event handler that runs when an element is no longer displayed in the viewable part of the current window.

Description

An element leaves the viewport when the page is scrolled so that the element is completely out of view. An element also leaves the viewport if it was shown or expanded and is then hidden or collapsed from the viewable part of the current window. onViewportLeave() is not fired for hidden or collapsed elements even if they are scrolled out of view.

Note

Deprecation note: The $w parameter of event handlers is being deprecated. To get a scoped selector for working with elements in repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context). To learn more, see here.

See Also

onViewportEnter( )

Syntax

function onViewportLeave(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the element leaves the viewport.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The element on which the event is now registered.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Get the ID of the element that has left the viewport

$w("#myElement").onViewportLeave( (event) => {
  let targetId = event.target.id; // "myElement"
});

pause( )

Pauses playback.

Description

The pause() function pauses the audio track and fires a pause event.

The pause event handlers set on the audio player by the onPause( ) function are called.

Syntax

function pause(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When playback has been paused.

Examples

Pause playback

$w("#myAudioPlayer").pause();

Pause playback and log a message when done

$w("#myAudioPlayer").pause()
  .then( () => {
    console.log("Done with pause");
  } );

play( )

Begins or resumes playback.

Description

The play() function plays the audio track and fires a play event.

The play event handlers set on the audio player by the onPlay( ) function are called.

Syntax

function play(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When playback begins or resumes.

Examples

Begin or resume playback

$w("#myAudioPlayer").play();

Begin or resume playback and log a message when done

$w("#myAudioPlayer").play()
  .then( () => {
    console.log("Done with play");
  } );

scrollTo( )

Scrolls the page to the element using an animation.

Description

The scrollTo() function returns a Promise that is resolved when the animated scroll is complete and the element is now in view.

To scroll to a specific location on the page, see the wix-window scrollTo() function.

Calling the scrollTo() function on an element in a repeated item that is selected from the global scope causes an error.

Syntax

function scrollTo(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the scroll is complete.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.Element

Examples

Scroll the page to an element

$w("#myElement").scrollTo();

Scroll the page to an element and log message when done

$w("#myElement").scrollTo()
  .then( ( ) => {
    console.log("Done with scroll");
} );

seek( )

Moves playback to the specified time, in seconds.

Syntax

function seek(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the playback has moved to the specified time.

Examples

Move playback to 1 minute and 42 seconds into the audio track

$w("#myAudioPlayer").seek(102);

Move playback and log a message when done

$w("#myAudioPlayer").seek(102)
  .then( () => {
    console.log("Done with seek");
  } );

show( )

Shows the element and sets its hidden property to false, using an effect if specified.

Description

The show() function shows the element and returns a Promise that is resolved when the effect is complete and the element's hidden property has been set to false.

You can optionally apply an effect when showing the element by providing an effectName value. You can also customize the effect by providing the optional effectOptions object.

Effects:

See Also

hide( ), hidden, expand( )

Syntax

function show([effectName: string], [effectOptions: ArcEffectOptions | BounceEffectOptions | FadeEffectOptions | FlipEffectOptions | FloatEffectOptions | FlyEffectOptions | FoldEffectOptions | GlideEffectOptions | PuffEffectOptions | RollEffectOptions | SlideEffectOptions | SpinEffectOptions | TurnEffectOptions | ZoomEffectOptions]): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the effect is complete and the element's hidden property has been set to false.

MIXED IN FROM

?
Where this functionality is inherited from.
$w.HiddenCollapsedMixin

Examples

Show an element with no effect

$w("#myElement").show();

Show an element with the "fade" effect

$w("#myElement").show("fade");

Show an element with the "fade" effect and custom options

let fadeOptions = {
  "duration":   2000,
  "delay":      1000
};

$w("#myElement").show("fade", fadeOptions);

Show an element with an effect and log a message when the effect is done

$w("#myElement").show("fade")
  .then( ( ) => {
    console.log("Done with fade");
  } );

Toggle an element's hidden state

if( $w("#myElement").hidden ) {
  $w("#myElement").show();
}
else {
  $w("#myElement").hide();
}

stop( )

Stops playback.

Description

The stop() function stops the playback, moves to the beginning of the audio track, and fires a pause event.

The pause event handlers set on the audio player by the onPause( ) function are called.

Syntax

function stop(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When playback has been stopped.

Examples

Stop playback

$w("#myAudioPlayer").stop();

Stop playback and log a message when done

$w("#myAudioPlayer").stop()
  .then( () => {
    console.log("Done with stop");
  } );

togglePlay( )

Toggles playback.

Description

The togglePlay() function either pauses or plays the current playback based on its current state:

  • If the playback is paused, it plays and a play event is fired. The play event handlers set on the audio player by the onPlay( ) function are called.
  • If the playback is playing, it is paused and a pause event is fired. The pause event handlers set on the audio player by the onPause( ) function are called.

Syntax

function togglePlay(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When playback has been toggled.

Examples

Toggle playback

$w("#myAudioPlayer").togglePlay();

Toggle playback and log a message when done

$w("#myAudioPlayer").togglePlay()
  .then( () => {
    console.log("Done with toggle play");
  } );

unmute( )

Unmutes audio volume.

Syntax

function unmute(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the volume has been unmuted.

Examples

Unmute volume

$w("#myAudioPlayer").unmute();

Unmute volume and log a message when done

$w("#myAudioPlayer").unmute()
  .then( () => {
    console.log("Done with unmute");
  } );