Closed g-van-vreckem closed 8 years ago
@g-van-vreckem good point, thanks - plugin now uses % in latest version. Will look at using transform as an option but did you test that code? I dropped it in and wasn't quite working so will need to look further at it. Feel free to test against the latest version and get back to me or submit a PR if you have time.
I made too much others changes removing jQuery and using animations to be sure, but the % must be calculated differently for transform and left/top. The * -100 / scaledImageHeight above was only good for transform use not left / top. Also, transform still need prefix for some plateforms so i use:
transform = Modernizr.prefixed( 'transform' ),
...
self.image.style[ transform ] = 'translate(' + hShift + '%,' + vShift + '%) translate3d(0,0,0)';
I've made a pull-request so you can look at a working solution based on your new code.
+1
Proof of concept: https://github.com/jonom/jquery-focuspoint/pull/26
see #28 Note: to use the patch supply the proper prefixed name for transform as a parameter. I'll add a demo with the code for that
It looks like jQuery is already doing the proper prefixing when using this syntax .css('transform', '...'); that simplify things a bit.
I've explored switching to translate in v2 but the disadvantage that brings is that you can't then apply additional transforms (such as scale) to an image easily. So I'm putting this on the shelf for now, but thanks for the input!
Replace
With
Or for the best performance, according to tweenlight: a combo of translate and translate3d
Using % intead of px will avoid to have to adjust the focus during a scaled resizing of the container such as perspective change.