Skip to content

img bind naturalWidth and naturalHeight #7771

@danbulant

Description

@danbulant

Describe the problem

Svelte doesn't allow binding to naturalWidth and naturalHeight of img tags. Those are read only properties that reflect the natural width of an image (it's native resolution).

Describe the proposed solution

I'd like to be able to bind to those properties, so I can get those values simply out of images.

<script>  let naturalWidth = 0; </script> <img src="something.jpg" bind:naturalWidth> The images natural width is {naturalWidth}

Alternatives considered

Without binding, I can react to onload and get the naturalWidth/naturalHeight there. Using binds seems more like "the svelte way".

<script>  let naturalWidth = 0;  function imageLoaded(e) { naturalWidth = e.target.naturalWidth } </script> <img src="something.jpg" on:load={imageLoaded}> The imaages natural width is {naturalWidth}

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions