Screenad API Event Reference

Screenad Event Details

onClickOut()

Category: Screenad

Is called when an exit click is performed. Use this event to collapse your expandable element or to stop playing a video.

Sample Usage:
screenad.onClickOut = function() {
    // perform collapse (example)
    doCollapse();
}
See Also:
screenad#CLICK_OUT

onHide()

Category: Screenad

Is called whenever the element is hidden (using a Screenad command).

See Also:
screenad#HIDE

onMouseLeave()

Category: Screenad

Is called when the mouse leaves the ad unit’s iframe.

Sample Usage:
screenad.onMouseLeave = function() {
    // e.g., Stop playing the video when the mouse leaves the iframe:
    exampleVideo.stop();
}
See Also:
screenad#MOUSE_LEAVE

onMouseMove(event)

Category: Screenad

Is called when mouse coordinates have changed, even outside of the viewport. To start tracking the mouse from outside the viewport, set screenad.settings.trackExternalMouse to true.

Sample Usage:
screenad.onMouseMove = function(event) {
    // You can use either screenad.mousex or event.mousex in this case.
    myExample.rotate(screenad.mouseAngle());
}
Parameters:
event
See Also:
screenad#MOUSE_MOVE

onOrientationChange()

Category: Environment

Is called whenever the browser or screen orientation changes (use screenad.screenorientation to get the latest value).

See Also:
screenad#ORIENTATION_CHANGE

onPreloadComplete()

Category: Communication

Is called when this ad element has preloaded. This is a good point to start your animations. Listen to the onSync event if your animation needs to run in sync with another ad element.

Sample Usage:
screenad.onPreloadComplete = function() {
    // e.g., Start animating
    startAnimation();
}
See Also:
screenad#conf_autopreload
screenad#PRELOAD_COMPLETE
screenad#setPreloaded

onResize()

Category: Environment

Is called whenever the browser or the element is resized.

Sample Usage:
screenad.onResize = function() {
    // Insert code to realign your ad's content.
}
See Also:
screenad#RESIZE

onScroll()

Category: Screenad

Is called when a page scroll occurs.

Sample Usage:
screenad.onScroll = function() {
    // e.g., Show a layer when scrolled past a certain point.
    if (screenad.scrolly > 400) {
        screenad.show();
    }
}
See Also:
screenad#SCROLL

onSetVariable(var_name)

Category: Communication

Is called when the element receives a variable from another element.

Sample Usage:
screenad.onSetVariable = function(var_name) {
    // Alert the (new) value of the received variable.
    alert(screenad.vars[var_name]);
}
Parameters:
{String} var_name
Name of the variable that was received; accessible through screenad.vars[var_name].
See Also:
screenad#SET_VARIABLE

onShow()

Category: Screenad

Is called whenever the element is shown (using a Screenad command).

See Also:
screenad#SHOW

onStateChange(state)

Category: Environment

Is called when the state of the element changes inside apps, e.g., screenad.STATE_EXPANDED, screenad.STATE_DEFAULT. This can be used to handle close commands that originate from the app itself.

Sample Usage:
screenad.onStateChange = function(state) {
    if (state === screenad.STATE_DEFAULT) {
        // Perform collapse (example).
        doCollapse();
    }
}
Parameters:
{String} state
The current state of the element.
See Also:
screenad#STATE_CHANGE

onSync()

Category: Communication

Is called when all elements inside this ‘ad position’ have sent the ‘preloaded’ command.

Sample Usage:
screenad.onSync = function() {
    // Start synchronized animation (sample).
    startAnimation();
}
See Also:
screenad#SYNC

onTilt(tiltX, tiltY, tiltZ)

Category: Environment

Is called when the MRAID Tilt event or a devicemotion event is dispatched.

Sample Usage:
screenad.onTilt = function(x, y, z) {
    // Do something with the x, y, z values.
}
Parameters:
{Number} tiltX
Device rotation on the X-axis.
{Number} tiltY
Device rotation on the Y-axis.
{Number} tiltZ
Device rotation on the Z-axis.
See Also:
screenad#TILT

onVisibilityChange()

Category: Environment

Is called when this ad has been scrolled into or out of the viewport (use screenad.hasVisibility to get the latest value).

See Also:
screenad#VISIBILITY_CHANGE