HTML styler
When styler is provided a HTMLElement, it returns a styler capable of setting CSS and scroll props.
const divStyler = styler(document.getElementByTag('div'))
divStyler.set({ x: 0, scale: 1.2 })Config
A configuration argument can be optionally passed to styler as the second argument:
const divStyler = styler(div, {});enableHardwareAcceleration
If set to false, Stylefire won’t optimise animations with the GPU.
This can result in higher image quality when scaling up elements.
Props
Property alias
The following alias’ can be optionally used for setting CSS props:
x:translateXy:translateYz:translateZoriginX:transformOriginXoriginY:transformOriginYoriginZ:transformOriginZ
If set as a number, originX and originY are set as a progress value between 0 and 1. originZ is set in pixels.
Transform property order
The transform property can be set directly, but in most cases it’s simpler to animate rotate, translate and scale as individual props.
In accordance with the CSS Transforms Level 2 spec, if set individually these properties will be set in the following order:
translate, scale, rotate
A different order can be specified by setting transform to a function. It’ll be provided two values, the individually-set props and the Stylefire-generated. transform.
styler.set({
transform: ({ x, y }, generated) => 'translateX' + x * y + 'px)'
})CSS variables
CSS variables can be set and animated just like any other property:
const htmlStyler = css(document.documentElement);
htmlRenderer.set('--bg-color', '#000');Supported props
All CSS properties are supported, in addition to these scroll properties:
scrollTopscrollLeft
If window is passed to styler, these are the only two supported props.
Prop types
For convenience and safety, many props are mapped to value types for safety and convenience.
Color props
color:colorbackgroundColor:coloroutlineColor:colorfill:colorstroke:color
Border props
borderColor:colorborderTopColor:colorborderRightColor:colorborderBottomColor:colorborderLeftColor:colorborderWidth:pxborderTopWidth:pxborderRightWidth:pxborderBottomWidth:pxborderLeftWidth:pxborderRadius:pxborderTopLeftRadius:pxborderTopRightRadius:pxborderBottomRightRadius:pxborderBottomLeftRadius:px
Positioning
width:px
maxWidth:px
height:px
maxHeight:px
top:pxleft:pxbottom:pxright:px
Transform
rotate:degreesrotateX:degreesrotateY:degreesrotateZ:degreesscale:scalescaleX:scalescaleY:scalescaleZ:scaleskewX:degreesskewY:degreestranslateX:pxtranslateY:pxtranslateZ:pxperspective:pxopacity:alpha
Spacing
padding:pxpaddingTop:pxpaddingRight:pxpaddingBottom:pxpaddingLeft:pxmargin:pxmarginTop:pxmarginRight:pxmarginBottom:pxmarginLeft:px