[][src]Struct moxie_dom::elements::media::ImgBuilder

#[must_use = "needs to be built"]pub struct ImgBuilder { /* fields omitted */ }

The HTML <img> element embeds an image into the document.

A type for initializing the element's attributes before calling build.

Implementations

impl ImgBuilder[src]

pub fn build(self) -> Img[src]

Initialize the element with all of the attributes so far.

impl ImgBuilder[src]

pub fn alt(self, to_set: impl ToString) -> Self[src]

Defines an alternative text description of the image.

Note: Browsers do not always display images. For example:

  • Non-visual browsers (such as those used by people with visual impairments)
  • The user chooses not to display images (saving bandwidth, privacy reasons)
  • The image is invalid or an unsupported type
  • In these cases, the browser may replace the image with the text in the element's alt attribute. For these reasons and others, provide a useful value for alt whenever possible.

Omitting alt altogether indicates that the image is a key part of the content and no textual equivalent is available. Setting this attribute to an empty string (alt="") indicates that this image is not a key part of the content (it’s decoration or a tracking pixel), and that non-visual browsers may omit it from rendering. Visual browsers will also hide the broken image icon if the alt is empty and the image failed to display.

This attribute is also used when copying and pasting the image to text, or saving a linked image to a bookmark.

pub fn crossorigin(self, to_set: impl ToString) -> Self[src]

Indicates if the fetching of the image must be done using a CORS request. Image data from a CORS-enabled image returned from a CORS request can be reused in the element without being marked "tainted".

If the crossorigin attribute is not specified, then a non-CORS request is sent (without the Origin request header), and the browser marks the image as tainted and restricts access to its image data, preventing its usage in elements.

If the crossorigin attribute is specified, then a CORS request is sent (with the Origin request header); but if the server does not opt into allowing cross-origin access to the image data by the origin site (by not sending any Access-Control-Allow-Origin response header, or by not including the site's origin in any Access-Control-Allow-Origin response header it does send), then the browser marks the image as tainted and restricts access to its image data, preventing its usage in elements.

Allowed values:

  • anonymous: A CORS request is sent with credentials omitted (that is, no cookies, X.509 certificates, or Authorization request header).
  • use-credentials: The CORS request is sent with any credentials included (that is, cookies, X.509 certificates, and the Authorization request header). If the server does not opt into sharing credentials with the origin site (by sending back the Access-Control-Allow-Credentials: true response header), then the browser marks the image as tainted and restricts access to its image data.

If the attribute has an invalid value, browsers handle it as if the anonymous value was used.

pub fn decoding(self, to_set: impl ToString) -> Self[src]

Provides an image decoding hint to the browser. Allowed values:

  • sync: Decode the image synchronously, for atomic presentation with other content.
  • async: Decode the image asynchronously, to reduce delay in presenting other content.
  • auto: Default: no preference for the decoding mode. The browser decides what is best for the user.

pub fn height(self, to_set: impl ToString) -> Self[src]

The intrinsic height of the image, in pixels. Must be an integer without a unit.

pub fn ismap(self, to_set: bool) -> Self[src]

Indicates that the image is part of a server-side map. If so, the coordinates where the user clicked on the image are sent to the server.

Note: This attribute is allowed only if the element is a descendant of an element with a valid href attribute. This gives users without pointing devices a fallback destination.

pub fn loading(self, to_set: impl ToString) -> Self[src]

Indicates how the browser should load the image:

  • eager: Loads the image immediately, regardless of whether or not the image is currently within the visible viewport (this is the default value).
  • lazy: Defers loading the image until it reaches a calculated distance from the viewport, as defined by the browser. The intent is to avoid the network and storage bandwidth needed to handle the image until it's reasonably certain that it will be needed. This generally improves the performance of the content in most typical use cases.

Note: Loading is only deferred when JavaScript is enabled. This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing images in a page's markup such that a server can track how many images are requested and when.

pub fn sizes(self, to_set: impl ToString) -> Self[src]

One or more strings separated by commas, indicating a set of source sizes. Each source size consists of:

  • A media condition. This must be omitted for the last item in the list.
  • A source size value.

Media Conditions describe properties of the viewport, not of the image. For example, (max-height: 500px) 1000px proposes to use a source of 1000px width, if the viewport is not higher than 500px.

Source size values specify the intended display size of the image. User agents use the current source size to select one of the sources supplied by the srcset attribute, when those sources are described using width (w) descriptors. The selected source size affects the intrinsic size of the image (the image’s display size if no CSS styling is applied). If the srcset attribute is absent, or contains no values with a width descriptor, then the sizes attribute has no effect.

pub fn src(self, to_set: impl ToString) -> Self[src]

The image URL. Mandatory for the element. On browsers supporting srcset, src is treated like a candidate image with a pixel density descriptor 1x, unless an image with this pixel density descriptor is already defined in srcset, or unless srcset contains w descriptors.

pub fn srcset(self, to_set: impl ToString) -> Self[src]

One or more strings separated by commas, indicating possible image sources for the user agent to use. Each string is composed of:

  • A URL to an image
  • Optionally, whitespace followed by one of:
    • A width descriptor (a positive integer directly followed by w). The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density.
    • A pixel density descriptor (a positive floating point number directly followed by x).
    • If no descriptor is specified, the source is assigned the default descriptor of 1x.

It is incorrect to mix width descriptors and pixel density descriptors in the same srcset attribute. Duplicate descriptors (for instance, two sources in the same srcset which are both described with 2x) are also invalid.

The user agent selects any of the available sources at its discretion. This provides them with significant leeway to tailor their selection based on things like user preferences or bandwidth conditions. See our Responsive images tutorial for an example.

pub fn width(self, to_set: impl ToString) -> Self[src]

The intrinsic width of the image in pixels. Must be an integer without a unit.

pub fn usemap(self, to_set: impl ToString) -> Self[src]

The partial URL (starting with #) of an image map associated with the element.

Note: You cannot use this attribute if the element is inside an or

Trait Implementations

impl Element for ImgBuilder[src]

impl<E> EventTarget<E> for ImgBuilder where
    E: GlobalEvent
[src]

impl GlobalEventHandler for ImgBuilder[src]

impl HtmlElement for ImgBuilder[src]

impl Node for ImgBuilder[src]

Auto Trait Implementations

impl !RefUnwindSafe for ImgBuilder

impl !Send for ImgBuilder

impl !Sync for ImgBuilder

impl Unpin for ImgBuilder

impl !UnwindSafe for ImgBuilder

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<N> Child for N where
    N: Node
[src]

impl<T> Downcast for T where
    T: Any

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.