top of page
Image Fit Mode

Image Fit Mode

Experiment with different ways to fit your image in an image element

Intermediate.png

Beginner

2K

Published:

November 8, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example you can test out the different Fit Mode API options available for images: fit, fill, and fixed width. You can use the default image or upload your own, and test how images appear in different orientations: portrait, landscape, and square. Then you can apply the fit mode option that works best for you to the images on your site.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It


Page Elements


We added the following elements to our page:

  • Upload button: For optionally uploading your own image

  • 2 sets of radio buttons: For choosing the image element orientation and the fit mode.

  • 3 image elements: portrait, landscape, and square orientation. Only 1 image displays at a time.

 

Code


Our code does the following:

  1. When the page is ready, declare and set the variables representing the currently selected options to default fit mode and orientation values: ‘fill’ and ‘portrait’.

  2. When a site visitor clicks the upload button, upload the file and set it as the source of the currently displayed image.

  3. When a site visitor selects a different fit mode option, apply the new fit mode to the current image and update the variable storing the current fit mode.

  4. When a site visitor selects a different orientation, do the following:

  5. Hide the container with the currently displayed image element.

  6. Store the value of the new orientation.

  7. Assign the image source and current fit mode to the new image element.

  8. Show the container with the new image element.

 

Note: Some fit mode options resize the image element, causing the image to change its orientation.

APIs We Used

Non-code example.

Non-code example.

Non-code example.

Related Articles

Article Link

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Image and Text Animation

Image and Text Animation

Use wix-animations API to animate images and text.

Intermediate.png

Intermediate

Hide and Show an Image

Hide and Show an Image

Show and hide an image according to the clicked button.

Intermediate.png

Beginner

Detect Image Labels

Detect Image Labels

Use Google’s vision NPM module to detect an image’s labels.

Intermediate.png

Advanced

Anchor 2
bottom of page