DOM.Surface Class
samsara/dom/Surface.js:11
Surface is a wrapper for a DOM element animated by Samsara.
Samsara will commit opacity, size and CSS3 transform
properties into the Surface.
CSS classes, properties and DOM attributes can also be added and dynamically changed.
Surfaces also act as sources for DOM events such as click
.
Constructor
DOM.Surface
-
[options]
Parameters:
-
[options]
Object optionalOptions
-
[size]
Number[] optionalSize (width, height) in pixels. These can also be
true
orundefined
. -
[classes]
String[] optionalCSS classes
-
[properties]
Object optionalDictionary of CSS properties
-
[attributes]
Object optionalDictionary of HTML attributes
-
[content]
optionalSstring} InnerHTML content
-
[origin]
Number[] optionalOrigin (x,y), with values between 0 and 1
-
[margins]
Number[] optionalMargins (x,y) in pixels
-
[proportions]
Number[] optionalProportions (x,y) with values between 0 and 1
-
[aspectRatio]
Number optionalAspect ratio
-
[opacity=1]
Number optionalOpacity
-
[tagName="div"]
String optionalHTML tagName
-
[enableScroll]
Boolean optionalAllows a Surface to support native scroll behavior
-
[roundToPixel]
Boolean optionalPrevents text-blurring if set to true, at the cost to jittery animation
-
Example:
var context = new Context()
var surface = new Surface({
content : 'Hello world!',
size : [true,100],
opacity : .5,
classes : ['myClass1', 'myClass2'],
properties : {background : 'red'}
});
context.add(surface);
context.mount(document.body);
// same as above but create an image instead
var surface = new Surface({
tagName : 'img',
attributes : {
src : 'cat.jpg'
},
size : [100,100]
});
Item Index
Methods
addClass
-
className
Add CSS class to the list of classes on this Surface.
Parameters:
-
className
StringClass name
attach
-
target
Assigns the DOM element for committing and to and attaches event listeners.
Parameters:
-
target
Nodedocument parent of this container
deploy
-
target
Insert the Surface's content into the currentTarget.
Parameters:
-
target
NodeDOM element to set content into
detach
()
private
Removes the associated DOM element in memory and detached event listeners.
emit
-
type
-
[payload]
Emit an event with optional data payload. This will execute all listening to the channel name with the payload as only argument.
getProperties
()
Object
Getter for CSS properties.
Returns:
Dictionary of this Surface's properties.
on
-
type
-
handler
Adds a handler to the type
channel which will be executed on emit
.
recall
-
target
Cache the content of the Surface in a document fragment for future deployment.
Parameters:
-
target
Node
remove
-
allocator
Remove all Samsara-relevant data from the Surface.
Parameters:
-
allocator
ElementAllocatorAllocator
removeClass
-
className
Remove CSS class from the list of classes on this Surface.
Parameters:
-
className
StringClass name
removeListener
-
type
-
handler
Removes a previously added handler to the type
channel.
Undoes the work of on
.
set
-
sources
Introduce new data streams to the layout node in {key : value} pairs.
Here the key
is one of "transform", "origin", "align" or "opacity".
The value
is either a stream, or a simple type like a Number
or Array
.
Simple types will be wrapped in an Observerable
to emit appropriate events.
Parameters:
-
sources
ObjectObject of data sources
setAspectRatio
-
aspectRatio
Setter for aspect ratio. If only one of width or height is specified, the aspect ratio will replace the unspecified dimension by scaling the specified dimension by the value provided.
Parameters:
-
aspectRatio
Number | StreamAspect ratio.
setAttributes
-
attributes
Setter for HTML attributes.
Parameters:
-
attributes
ObjectHTML Attributes
setContent
-
content
Set or overwrite innerHTML content of this Surface.
Parameters:
-
content
String | DocumentFragmentHTML content
setMargins
-
margins
Setter for margins.
Parameters:
-
margins
Number[] | StreamMargins as [width, height] in pixels, or a stream.
setOptions
-
options
Set options for this surface
Parameters:
-
options
ObjectOverrides for default options. See constructor.
setOrigin
-
origin
Setter for origin.
Parameters:
-
origin
Number[] | StreamOrigin as [x,y], or a stream.
setProperties
-
properties
Setter for CSS properties. Note: properties are camelCased, not hyphenated.
Parameters:
-
properties
ObjectCSS properties
setProportions
-
proportions
Setter for proportions.
Parameters:
-
proportions
Number[] | StreamProportions as [x,y], or a stream.
setSize
-
size
Setter for size.
Parameters:
-
size
Number[] | StreamSize as [width, height] in pixels, or a stream.
setup
-
allocator
Allocates the element-type associated with the Surface, adds its given element classes, and prepares it for future committing.
This method is called upon the first start
or resize
event the Surface gets.
Parameters:
-
allocator
ElementAllocatorAllocator
toggleClass
-
className
Toggle CSS class for this Surface.
Parameters:
-
className
StringClass name