peel.js
    Preparing search index...

    Class Peel

    Main class that controls the peeling effect.

    Index

    Constructors

    • The constructor will look for the required elements to make the peel effect in the options, and create them if they do not exist.

      Parameters

      • el: string | HTMLElement
      • options: Partial<PeelOptions> = {}

      Returns Peel

    Properties

    el: HTMLElement
    options: PeelOptions
    constraints: Circle[]
    corner: Point
    path?: LineSegment | BezierCurve
    dragHandler?: Handler
    pressHandler?: Handler
    timeAlongPath?: number
    peelLineSegment?: LineSegment
    peelLineRotation: number = 0
    width: number = 0
    height: number = 0
    elementBox: any
    flipConstraint?: Circle
    clippingBox: any
    topClip: any
    backClip: any
    topLayer?: HTMLElement
    backLayer: HTMLElement
    bottomLayer?: HTMLElement
    topShapeClip?: SVGClip
    backShapeClip?: SVGClip
    bottomShapeClip?: SVGClip
    topShadowElement: HTMLElement
    backShadowElement?: HTMLElement
    backReflectionElement?: HTMLElement
    bottomShadowElement?: HTMLElement
    usesBoxShadow?: boolean
    center: Point
    defaultOptions: {
        corner:
            | [number, number]
            | TOP_LEFT
            | TOP_RIGHT
            | BOTTOM_LEFT
            | BOTTOM_RIGHT
            | { x: number; y: number };
        fadeThreshold: number;
        topShadow: boolean;
        topShadowBlur: number;
        topShadowAlpha: number;
        topShadowOffsetX: number;
        topShadowOffsetY: number;
        topShadowCreatesShape: boolean;
        backReflection: boolean;
        backReflectionSize: number;
        backReflectionOffset: number;
        backReflectionAlpha: number;
        backReflectionDistribute: boolean;
        backShadow: boolean;
        backShadowSize: number;
        backShadowOffset: number;
        backShadowAlpha: number;
        backShadowDistribute: boolean;
        bottomShadow: boolean;
        bottomShadowSize: number;
        bottomShadowOffset: number;
        bottomShadowDarkAlpha: number;
        bottomShadowLightAlpha: number;
        bottomShadowDistribute: boolean;
        setPeelOnInit: boolean;
        clippingBoxScale: number;
        flipConstraintOffset: number;
        dragPreventsDefault: boolean;
        preset: "calendar" | "book" | undefined;
    } = ...

    Type Declaration

    • corner:
          | [number, number]
          | TOP_LEFT
          | TOP_RIGHT
          | BOTTOM_LEFT
          | BOTTOM_RIGHT
          | { x: number; y: number }

      Sets the corner for the effect to peel back from.

      PeelCorners.BOTTOM_RIGHT

    • fadeThreshold: number

      Threshold above which the top layer (including the backside) layer will begin to fade out. This is calculated based on the visible clipped area of the polygon. If a peel path is set, it will use the progress along the path instead.

    • topShadow: boolean

      Creates a shadow effect on the top layer of the peel. This may be a box-shadow or drop-shadow (filter) depending on the shape of the clipping.

    • topShadowBlur: number
    • topShadowAlpha: number
    • topShadowOffsetX: number
    • topShadowOffsetY: number
    • topShadowCreatesShape: boolean

      When a complex (non-rectangular) shape is used for the clipping effect, if this option is true another SVG shape will be embedded in the top layer to be used as the drop shadow. This is required for the drop-shadow filter effect but can be turned off here as the drop shadow effect can sometimes produce odd results.

    • backReflection: boolean

      Creates a shiny effect on the back layer of the peel.

    • backReflectionSize: number
    • backReflectionOffset: number
    • backReflectionAlpha: number
    • backReflectionDistribute: boolean

      When true, the reflection effect will reach its maximum halfway through the peel, then diminish again. If false, it will continue to grow as the peel advances.

    • backShadow: boolean

      Creates a shadow effect on the back layer of the peel.

    • backShadowSize: number
    • backShadowOffset: number
    • backShadowAlpha: number
    • backShadowDistribute: boolean

      When true, the back shadow effect will reach its maximum halfway through the peel, then diminish again. If false, it will continue to grow as the peel advances. "Book" mode sets this to false so that the effect can still have some depth when the book is "fully open".

    • bottomShadow: boolean

      Creates a shadow effect on the bottom layer of the peel.

    • bottomShadowSize: number
    • bottomShadowOffset: number
    • bottomShadowDarkAlpha: number

      Alpha value (color is black) of the dark shadow on the bottom layer.

    • bottomShadowLightAlpha: number

      Alpha value (color is black) of the light shadow on the bottom layer.

    • bottomShadowDistribute: boolean

      When true, the bottom shadow effect will reach its maximum halfway through the peel, then diminish again. If false, it will continue to grow as the peel advances. "Book" mode sets this to false so that the effect can still have some depth when the book is "fully open".

    • setPeelOnInit: boolean

      If true, the peel effect will be set to its relative corner on initialization.

    • clippingBoxScale: number

      Sets the scale of the clipping box around the element. Default is 4, which means 4 times the element size. This allows the effects like box shadow to be seen even when the upper layer falls outsize the element boundaries. Setting this too high may encounter odd effects with clipping.

    • flipConstraintOffset: number

      When constraining the peel, the effect will "flip" around the axis of the constraint, which tends to look unnatural. This offset will pull the corner in a few pixels when approaching the axis line, which results in a smoother transition instead of a sudden flip. The value here determines how many pixels the corner is pulled in.

    • dragPreventsDefault: boolean

      Whether initiating a drag event (by mouse or touch) will call preventDefault on the original event.

    • preset: "calendar" | "book" | undefined

    Methods

    • Parameters

      • preset: "calendar" | "book"

      Returns void

    • Sets a path along which the peel will follow. Can be a flat line segment or a bezier curve.

      Parameters

      • ...args:
            | [number, number, number, number]
            | [number, number, number, number, number, number, number, number]

      Returns void

    • Sets a function to be called when the user either presses or drags.

      Parameters

      • event: "drag" | "press"
      • fn: Handler

        The function to be called on press. This function will be called with the original event as the first argument, and the x, y coordinates of the event as the 2nd and 3rd arguments, respectively.

      • Optionalel: HTMLElement

        The element to initiate the event. If not passed, this will be the element associated with the Peel instance. Allowing this to be passed lets another element serve as a "hit area" that can be larger than the element itself.

      Returns void

    • Returns void

    • Sets the peel effect to a point in time along a previously specified path. Will throw an error if no path exists.

      Parameters

      • t: any

      Returns void

    • Sets the position of the peel effect. This point is the position of the corner that is being peeled back.

      Parameters

      • ...args:
            | readonly [number, number]
            | readonly [
                | | [number, number]
                | TOP_LEFT
                | TOP_RIGHT
                | BOTTOM_LEFT
                | BOTTOM_RIGHT
                | { x: number; y: number }
                | Point,
            ]

      Returns void

    • Sets a constraint on the distance of the peel. This can be thought of as a point on the layers that are connected and cannot be torn apart. Typically this only makes sense as a point on the outer edge, such as the left edge of an open book, or the top edge of a calendar. In this case, simply using 2 constraint points (top-left/bottom-left for a book, etc) will create the desired effect. An arbitrary point can also be used with an effect like a thumbtack holding the pages together.

      Parameters

      • ...args:
            | readonly [number, number]
            | readonly [
                | | [number, number]
                | TOP_LEFT
                | TOP_RIGHT
                | BOTTOM_LEFT
                | BOTTOM_RIGHT
                | { x: number; y: number }
                | Point,
            ]

      Returns void

    • Gets the ratio of the area of the clipped top layer to the total area. This is used to calculate a fade threshold.

      Returns number

      A value between 0 and 1.

    • Parameters

      • ...args:
            | readonly [number, number]
            | readonly [
                | | [number, number]
                | TOP_LEFT
                | TOP_RIGHT
                | BOTTOM_LEFT
                | BOTTOM_RIGHT
                | { x: number; y: number }
                | Point,
            ]

      Returns Point