Created
November 6, 2012 00:46
-
-
Save bdalziel/4021633 to your computer and use it in GitHub Desktop.
Zoom and position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var performZoomAndPositionImg = function (newZoomLevel) { | |
var zoomScaleContainer = Y.one('.fullScreenGallery .fullScreenExperience'); | |
var zoomBoundary = zoomScaleContainer.one('.zoomBoundary'); | |
var zoomImage = zoomBoundary.one('.zoomImg'); | |
var oldLeftOffset = zoomImage.get('offsetLeft'); | |
var oldTopOffset = zoomImage.get('offsetTop'); | |
var oldImgHeight = zoomImage.get('offsetHeight'); | |
var oldBoundaryHeight = zoomBoundary.get('offsetHeight'); | |
Y.Util.replaceClassValue(zoomScaleContainer, 'zoom', newZoomLevel); | |
var newImgHeight = zoomImage.get('offsetHeight'); | |
var newBoundaryHeight = zoomBoundary.get('offsetHeight'); | |
var marginalScaleFactor = | |
(newBoundaryHeight - newImgHeight)/(oldBoundaryHeight - oldImgHeight); | |
var newLeftOffset = Math.round(oldLeftOffset * marginalScaleFactor); | |
var newTopOffset = Math.round(oldTopOffset * marginalScaleFactor); | |
Y.log("Zoom scale step: " + marginalScaleFactor + ". Img H=" + oldImgHeight + "->" + newImgHeight + ". Bound=" + oldBoundaryHeight + "->" + newBoundaryHeight + ". Left=" + oldLeftOffset + "->" + newLeftOffset + ". Top=" + oldTopOffset + "->" + newTopOffset); | |
var newLeftOffset = (newLeftOffset + 'px'); | |
var newTopOffset = (newTopOffset + 'px'); | |
zoomImage.setStyles({ | |
'left': newLeftOffset, | |
'top': newTopOffset | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment