Skip to content

Added ability to specify units as "pixels" or "percentage"#16

Open
bcole808 wants to merge 1 commit intokentor:masterfrom
bcole808:master
Open

Added ability to specify units as "pixels" or "percentage"#16
bcole808 wants to merge 1 commit intokentor:masterfrom
bcole808:master

Conversation

@bcole808
Copy link
Copy Markdown

Great jQuery plugin!

I am using block elements with an intrinsic aspect ratio in order to display responsive image spaces where the user has adjusted the image position using this jQuery plugin.

Problem

Background images positioned using pixels and background-size: cover only look correct when the image container remains exactly the same size.

Solution

Using percentages for background position allows the background to be in the correct space, regardless of element size.

Implementation

The code I added to the plugin adds an option called units which lets the developer specify "pixels" or "percent" and if percent is configured then the plugin will convert to percent before applying the styles.

@julianlam
Copy link
Copy Markdown

Are there plans to get this merged? Would be backwards compatible if "px" is defaulted if no units are passed in.

This is important for my use case, where a dragged picture's position changes significantly if the background-size is set to cover, as when browser is resized, the dimensions of the image itself have changed, but the saved position is still in reference to the old image dimensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants