Added ability to specify units as "pixels" or "percentage" #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.