Class sap.m.ImageModule: sap/m/Image
A wrapper around the IMG tag. The image can be loaded from a remote or local server.
Density related image will be loaded if image with density awareness name in format [imageName]@[densityValue].[extension] is provided. The valid desity values are 1, 1.5, 2. If the original devicePixelRatio isn't one of the three valid numbers, it's rounded up to the nearest one.
There are various size setting options available, and the images can be combined with actions.
From version 1.30, new image mode sap.m.ImageMode.Background is added. When this mode is set, the src property is set using the css style 'background-image'. The properties 'backgroundSize', 'backgroundPosition', 'backgroundRepeat' have effect only when image is in sap.m.ImageMode.Background mode. In order to make the high density image correctly displayed, the 'backgroundSize' should be set to the dimension of the normal density version.
sClassName
and enriches it with the information contained in oClassInfo
.fnFunction
to the error
event of this sap.m.Image
.fnFunction
to the load
event of this sap.m.Image
.fnFunction
to the press
event of this sap.m.Image
.fnFunction
to the tap
event of this sap.m.Image
.fnFunction
from the error
event of this sap.m.Image
.fnFunction
from the load
event of this sap.m.Image
.fnFunction
from the press
event of this sap.m.Image
.fnFunction
from the tap
event of this sap.m.Image
. Accepts an object literal mSettings
that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject for a general description of the syntax of the settings object.
The supported settings are:
- Properties
- src : sap.ui.core.URI
- width : sap.ui.core.CSSSize
- height : sap.ui.core.CSSSize
- decorative : boolean (default: true)
- alt : string
- useMap : string
- densityAware : boolean (default: true)
- activeSrc : sap.ui.core.URI (default: )
- mode : sap.m.ImageMode (default: Image)
- backgroundSize : string (default: cover)
- backgroundPosition : string (default: initial)
- backgroundRepeat : string (default: no-repeat)
- Events
- tap : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
- press : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
- load : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
- error : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.
{string} | sId? | id for the new control, generated automatically if no id is given |
{object} | mSettings? | initial settings for the new control |
{sap.ui.base.Event} | oControlEvent | |
{sap.ui.base.EventProvider} | oControlEvent.getSource | |
{object} | oControlEvent.getParameters |
- Since:
- 1.36.2
{sap.ui.base.Event} | oControlEvent | |
{sap.ui.base.EventProvider} | oControlEvent.getSource | |
{object} | oControlEvent.getParameters |
- Since:
- 1.36.2
{sap.ui.base.Event} | oControlEvent | |
{sap.ui.base.EventProvider} | oControlEvent.getSource | |
{object} | oControlEvent.getParameters |
{sap.ui.base.Event} | oControlEvent | |
{sap.ui.base.EventProvider} | oControlEvent.getSource | |
{object} | oControlEvent.getParameters |
sClassName
and enriches it with the information contained in oClassInfo
. oClassInfo
might contain the same kind of information as described in sap.ui.core.Control.extend.
{string} | sClassName | Name of the class being created |
{object} | oClassInfo? | Object literal with information about the class |
{function} | FNMetaImpl? | Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata |
{function} | Created class / constructor function |
{sap.ui.base.Metadata} | Metadata object describing this class |
fnFunction
to the error
event of this sap.m.Image
. When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.m.Image
itself.
Event is fired when the image resource can't be loaded. If densityAware is set to true, the event is fired when none of the fallback resources can be loaded.
{object} | oData? | An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
{function} | fnFunction | The function to be called when the event occurs |
{object} | oListener? | Context object to call the event handler with. Defaults to this sap.m.Image itself |
- Since:
- 1.36.2
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
to the load
event of this sap.m.Image
. When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.m.Image
itself.
Event is fired when the image resource is loaded.
{object} | oData? | An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
{function} | fnFunction | The function to be called when the event occurs |
{object} | oListener? | Context object to call the event handler with. Defaults to this sap.m.Image itself |
- Since:
- 1.36.2
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
to the press
event of this sap.m.Image
. When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.m.Image
itself.
Event is fired when the user clicks on the control.
{object} | oData? | An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
{function} | fnFunction | The function to be called when the event occurs |
{object} | oListener? | Context object to call the event handler with. Defaults to this sap.m.Image itself |
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
to the tap
event of this sap.m.Image
. When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.m.Image
itself.
Event is fired when the user clicks on the control. (This event is deprecated, use the press event instead)
{object} | oData? | An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
{function} | fnFunction | The function to be called when the event occurs |
{object} | oListener? | Context object to call the event handler with. Defaults to this sap.m.Image itself |
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
from the error
event of this sap.m.Image
. The passed function and listener object must match the ones used for event registration.
{function} | fnFunction | The function to be called, when the event occurs |
{object} | oListener | Context object on which the given function had to be called |
- Since:
- 1.36.2
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
from the load
event of this sap.m.Image
. The passed function and listener object must match the ones used for event registration.
{function} | fnFunction | The function to be called, when the event occurs |
{object} | oListener | Context object on which the given function had to be called |
- Since:
- 1.36.2
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
from the press
event of this sap.m.Image
. The passed function and listener object must match the ones used for event registration.
{function} | fnFunction | The function to be called, when the event occurs |
{object} | oListener | Context object on which the given function had to be called |
{sap.m.Image} | Reference to this in order to allow method chaining |
fnFunction
from the tap
event of this sap.m.Image
. The passed function and listener object must match the ones used for event registration.
{function} | fnFunction | The function to be called, when the event occurs |
{object} | oListener | Context object on which the given function had to be called |
{sap.m.Image} | Reference to this in order to allow method chaining |
error
to attached listeners. {Map} | mArguments? | The arguments to pass along with the event |
- Since:
- 1.36.2
{sap.m.Image} | Reference to this in order to allow method chaining |
load
to attached listeners. {Map} | mArguments? | The arguments to pass along with the event |
- Since:
- 1.36.2
{sap.m.Image} | Reference to this in order to allow method chaining |
press
to attached listeners. {Map} | mArguments? | The arguments to pass along with the event |
{sap.m.Image} | Reference to this in order to allow method chaining |
tap
to attached listeners. {Map} | mArguments? | The arguments to pass along with the event |
{sap.m.Image} | Reference to this in order to allow method chaining |
activeSrc
. The source property which is used when the image is pressed.
Default value is .
{sap.ui.core.URI} | Value of property activeSrc |
alt
. The alternative text that is displayed in case the Image is not available, or cannot be displayed. If the image is set to decorative this property is ignored.
{string} | Value of property alt |
backgroundPosition
. Defines the position of the image in sap.m.ImageMode.Background mode. This property is set on the output DOM element using CSS style 'background-position'. This property takes effect only when the 'mode' property is set to sap.m.ImageMode.Background.
Default value is initial
.
- Since:
- 1.30.0
{string} | Value of property backgroundPosition |
backgroundRepeat
. Defines whether the source image is repeated when the output DOM element is bigger than the source. This property is set on the output DOM element using CSS style 'background-repeat'. This property takes effect only when the 'mode' property is set to sap.m.ImageMode.Background.
Default value is no-repeat
.
- Since:
- 1.30.0
{string} | Value of property backgroundRepeat |
backgroundSize
. Defines the size of the image in sap.m.ImageMode.Background mode. This property is set on the output DOM element using CSS style 'background-size'. This property takes effect only when the 'mode' property is set to sap.m.ImageMode.Background.
Default value is cover
.
- Since:
- 1.30.0
{string} | Value of property backgroundSize |
decorative
. A decorative image is included for design reasons. Accessibility tools will ignore decorative images.
Note: If the Image has an image map (useMap is set), this property will be overridden (the image will not be rendered as decorative). A decorative image has no ALT attribute, so the Alt property is ignored if the image is decorative.
Default value is true
.
{boolean} | Value of property decorative |
densityAware
. If this is set to false, the src image will be loaded directly without attempting to fetch the density perfect image for high density device.
By default, this is set to true but then one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server.
If bandwidth is the key for the application, set this value to false.
Default value is true
.
{boolean} | Value of property densityAware |
height
. When the empty value is kept, the original size is not changed. It is also possible to make settings for width or height only, the original ratio between width/height is maintained. When 'mode' property is set to sap.m.ImageMode.Background, this property always needs to be set. Otherwise the output DOM element has a 0 size.
{sap.ui.core.CSSSize} | Value of property height |
mode
. Defines how the src and the activeSrc is output to the Dom Element. When set to sap.m.ImageMode.Image which is the default value, the src (activeSrc) is set to the 'src' attribute of the 'img' tag. When set to sap.m.ImageMode.Background, the src (activeSrc) is set to the CSS style 'background-image' and the root DOM element is rendered as a 'span' tag instead of an 'img' tag.
Default value is Image
.
- Since:
- 1.30.0
{sap.m.ImageMode} | Value of property mode |
src
. Relative or absolute path to URL where the image file is stored. The path will be adapted to the density aware format according to the density of the device following the convention that [imageName]@[densityValue].[extension]
{sap.ui.core.URI} | Value of property src |
useMap
. The name of the image map that defines the clickable areas
{string} | Value of property useMap |
width
. When the empty value is kept, the original size is not changed. It is also possible to make settings for width or height only, the original ratio between width/height is maintained. When 'mode' property is set to sap.m.ImageMode.Background, this property always needs to be set. Otherwise the output DOM element has a 0 size.
{sap.ui.core.CSSSize} | Value of property width |
{sap.ui.core.URI} | sActiveSrc |
alt
. The alternative text that is displayed in case the Image is not available, or cannot be displayed. If the image is set to decorative this property is ignored.
When called with a value of null
or undefined
, the default value of the property will be restored.
{string} | sAlt | New value for property alt |
{sap.m.Image} | Reference to this in order to allow method chaining |
backgroundPosition
. Defines the position of the image in sap.m.ImageMode.Background mode. This property is set on the output DOM element using CSS style 'background-position'. This property takes effect only when the 'mode' property is set to sap.m.ImageMode.Background.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is initial
.
{string} | sBackgroundPosition | New value for property backgroundPosition |
- Since:
- 1.30.0
{sap.m.Image} | Reference to this in order to allow method chaining |
backgroundRepeat
. Defines whether the source image is repeated when the output DOM element is bigger than the source. This property is set on the output DOM element using CSS style 'background-repeat'. This property takes effect only when the 'mode' property is set to sap.m.ImageMode.Background.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is no-repeat
.
{string} | sBackgroundRepeat | New value for property backgroundRepeat |
- Since:
- 1.30.0
{sap.m.Image} | Reference to this in order to allow method chaining |
backgroundSize
. Defines the size of the image in sap.m.ImageMode.Background mode. This property is set on the output DOM element using CSS style 'background-size'. This property takes effect only when the 'mode' property is set to sap.m.ImageMode.Background.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is cover
.
{string} | sBackgroundSize | New value for property backgroundSize |
- Since:
- 1.30.0
{sap.m.Image} | Reference to this in order to allow method chaining |
decorative
. A decorative image is included for design reasons. Accessibility tools will ignore decorative images.
Note: If the Image has an image map (useMap is set), this property will be overridden (the image will not be rendered as decorative). A decorative image has no ALT attribute, so the Alt property is ignored if the image is decorative.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is true
.
{boolean} | bDecorative | New value for property decorative |
{sap.m.Image} | Reference to this in order to allow method chaining |
densityAware
. If this is set to false, the src image will be loaded directly without attempting to fetch the density perfect image for high density device.
By default, this is set to true but then one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server.
If bandwidth is the key for the application, set this value to false.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is true
.
{boolean} | bDensityAware | New value for property densityAware |
{sap.m.Image} | Reference to this in order to allow method chaining |
height
. When the empty value is kept, the original size is not changed. It is also possible to make settings for width or height only, the original ratio between width/height is maintained. When 'mode' property is set to sap.m.ImageMode.Background, this property always needs to be set. Otherwise the output DOM element has a 0 size.
When called with a value of null
or undefined
, the default value of the property will be restored.
{sap.ui.core.CSSSize} | sHeight | New value for property height |
{sap.m.Image} | Reference to this in order to allow method chaining |
mode
. Defines how the src and the activeSrc is output to the Dom Element. When set to sap.m.ImageMode.Image which is the default value, the src (activeSrc) is set to the 'src' attribute of the 'img' tag. When set to sap.m.ImageMode.Background, the src (activeSrc) is set to the CSS style 'background-image' and the root DOM element is rendered as a 'span' tag instead of an 'img' tag.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is Image
.
{sap.m.ImageMode} | sMode | New value for property mode |
- Since:
- 1.30.0
{sap.m.Image} | Reference to this in order to allow method chaining |
{sap.ui.core.URI} | sSrc |
useMap
. The name of the image map that defines the clickable areas
When called with a value of null
or undefined
, the default value of the property will be restored.
{string} | sUseMap | New value for property useMap |
{sap.m.Image} | Reference to this in order to allow method chaining |
width
. When the empty value is kept, the original size is not changed. It is also possible to make settings for width or height only, the original ratio between width/height is maintained. When 'mode' property is set to sap.m.ImageMode.Background, this property always needs to be set. Otherwise the output DOM element has a 0 size.
When called with a value of null
or undefined
, the default value of the property will be restored.
{sap.ui.core.CSSSize} | sWidth | New value for property width |
{sap.m.Image} | Reference to this in order to allow method chaining |