Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noScroll flag and align an image to the center of the window. #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions intense.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ var Intense = (function() {

// Overflow variable before screen is locked.
var overflowValue;


// if the image size is smaller than the browser window size.
var noScroll = false;
var active = false;

/* -------------------------
Expand Down Expand Up @@ -266,6 +268,7 @@ var Intense = (function() {
stop();
document.body.removeChild(container);
active = false;
noScroll = false;
setState(false);
}

Expand All @@ -276,6 +279,13 @@ var Intense = (function() {
target.height = imageDimensions.h;
horizontalOrientation = imageDimensions.fit;

// check sourceimage dimensions and if are smaller than the window sizes, set the target size is source size;
if ( window.innerWidth > sourceDimensions.w && window.innerHeight > sourceDimensions.h ) {
target.width = sourceDimensions.w;
target.height = sourceDimensions.h;
noScroll = true;
}

targetDimensions = { w: target.width, h: target.height };
containerDimensions = { w: window.innerWidth, h: window.innerHeight };
overflowArea = {
Expand Down Expand Up @@ -353,7 +363,15 @@ var Intense = (function() {
if (horizontalOrientation === true) {
// HORIZONTAL SCANNING
currentPosition += mouse.xCurr - currentPosition;
if (mouse.xCurr !== lastPosition) {

if (noScroll) { // if noScroll is TRUE, Centering the image.
position = containerDimensions.w/2 - targetDimensions.w/2;
var targetY = containerDimensions.h/2 - targetDimensions.h/2;
target.style["webkitTransform"] = "translate(" + position + "px, " + targetY +"px)";
target.style["MozTransform"] = "translate(" + position + "px, " + targetY +"px)";
target.style["msTransform"] = "translate(" + position + "px, " + targetY +"px)";
lastPosition = mouse.xCurr;
} else if (mouse.xCurr !== lastPosition) {
var position = parseFloat(
calcPosition(currentPosition, containerDimensions.w)
);
Expand Down