jquery-draggable-background
jquery-draggable-background copied to clipboard
Added ability to specify units as "pixels" or "percentage"
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.
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.