So here is my code. I would like feedback on things I can improve. If you want to see the full example onin action, here is the link. And here is the js code
JQuery jQuery carousel code review
JQuery carousel code review
So here is my code. I would like feedback on things I can improve. If you want to see the full example on action here is the link. And here is the js code
jQuery carousel code
I would like feedback on things I can improve. If you want to see the full example in action, here is the link.
$(document).ready(function() {
var all = $("#slider-view");
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
$(all).css('height', window.innerHeight);
$(all).css('width', window.innerWidth);
// Assigns the container that has all the sections that will be scrolled horizontally
var sliderH = $('.nav-h');
var sliderVMiddle = $('.nav-v-middle');
var sliderVLast = $('.nav-v-last');
// Gets the number of slides of the horizontal slider
var sliderCountH = $('.nav-h').children().size();
var sliderCountVMiddle = $('.nav-v-middle').children().size();
var sliderCountVLast = $('.nav-v-last').children().size();
// Sets the properties of the arrows that have the events
setCssRect(sliderH, 'w', winWidth);
setCssRect(sliderH, 'h', winHeight);
setCssRect(sliderVMiddle, 'w', winWidth);
setCssRect(sliderVMiddle, 'h', winHeight);
setCssRect(sliderVLast, 'w', winWidth);
setCssRect(sliderVLast, 'h', winHeight);
// sets css size properties on the jQuery element.
function setCssRect(elt, property, value) {
if(property=='w') {
$('> div',elt).css('width', value);
}
else {$('> div',elt).css('height', value);}
}
// Gets the number of Horizontal or Vertical slide
var viewWidth = sliderCountH * winWidth;
var heightVMiddle = sliderCountVMiddle * winHeight;
var heightVLast = sliderCountVLast * winHeight;
// Sets the width and height for the Horizontal and Vertical slides
$('.nav-h').css('width', viewWidth);
$('.nav-v-middle').css('height', heightVMiddle);
$('.nav-v-last').css('height', heightVLast);
var isMobile = {
Android: function() { return navigator.userAgent.match(/Android/i); },
BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); },
iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); },
Opera: function() { return navigator.userAgent.match(/Opera Mini/i); },
Windows: function() { return navigator.userAgent.match(/IEMobile/i); },
any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); }
};
if ( isMobile.any() ) {
$('a#prevh').toggle();
$('a#nexth').toggle();
$('a#prevv').toggle();
$('a#nextv').toggle();
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
// actions for the swiperight
$(sliderH).hammer({prevent_default:true}).on('swiperight', function() {
actionHorizontalAnimation(0, '+', '+');
});
// Actions for the swipeLeft
$(sliderH).hammer({prevent_default:true}).on('swipeleft', function() {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
// Actions for the swipeUp
$(sliderH).hammer({prevent_default:true}).on('swipedown', function() {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
// Actions for the swipeDown
$(sliderH).hammer({prevent_default:true}).on('swipeup', function() {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
else {
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
$('a#prevh').on('click', function(event) {
actionHorizontalAnimation(0, '+', '+');
});
$('a#nexth').on('click', function(event) {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
$('a#prevv').on('click', function(event) {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
$('a#nextv').on('click', function(event) {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
// Onclick horizontal movement
function actionHorizontalAnimation(sliderPosition, orientation, shift) {
if(verticalIndexMiddle!==0) {
verticalAnimation(sliderVMiddle, '+', (winHeight*verticalIndexMiddle))
verticalIndexMiddle = 0;
}
if(verticalIndexLast!==0) {
verticalAnimation(sliderVLast, '+', (winHeight*verticalIndexLast))
verticalIndexLast = 0;
}
if(horizontalIndex!==sliderPosition) {
horizontalAnimation(sliderH, shift, winWidth);
if(orientation==='-'){horizontalIndex+=1;}else{horizontalIndex-=1;}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// OnClick vertical movement
function actionVerticalAnimation(middleSlidePosition, lastSlidePosition, orientation) {
if(horizontalIndex==1) {
if(verticalIndexMiddle!==middleSlidePosition) {
verticalAnimation(sliderVMiddle, orientation, winHeight);
if(orientation==='-'){verticalIndexMiddle+=1;} else {verticalIndexMiddle-=1;}
}
}
else if (horizontalIndex==2) {
if(verticalIndexLast!==lastSlidePosition) {
verticalAnimation(sliderVLast, orientation, winHeight)
if(orientation==='-'){verticalIndexLast+=1;} else {verticalIndexLast-=1;}
}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// animation for vertical slide
function verticalAnimation(slider, action, size) {
$('> div', slider).animate({
top: action+'=' + size
}, 600);
}
// animation for horizontal slide
function horizontalAnimation(slider, action, size) {
$('> div', slider).animate({
left: action+'=' + size
}, 600);
}
// Set hides or shows the arrows for the navigation
function findSlidePosition(h1, v1, v2) {
$('.nav-btns div').css('border-color', '#706E6D');
resetObjectStyle();
if(h1==0 && v1==0 && v2==0) {
$('.nav-home').css('border-color','#FFF');
activateControlFlow(['#nexth']);
}
else if(h1==1 && v1==0 && v2==0) {
$('.nav-middle-slide1').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv']);
}
else if(h1==1 && v1>=1 && v1<=8 && v2==0) {
var test = '.nav-middle-slide'+ (v1+1);
$(test).css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv', '#prevv']);
}
else if(h1==1 && v1==9 && v2==0) {
$('.nav-middle-slide10').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#prevv']);
}
else if(h1==2 && v1==0 && v2==0) {
$('.nav-last-slide1').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv']);
}
else if(h1==2 && v1==0 && (v2==1 || v2==2)) {
$('.nav-last-slide2').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv', '#prevv']);
}
else if(h1==2 && v1==0 && v2==3) {
$('.nav-last-slide4').css('border-color','#FFF');
activateControlFlow(['#prevh', '#prevv']);
}
}
// Hides all the arrows
function resetObjectStyle() {
$('a.control-flow').css({color:'transparent', cursor: 'auto'});
}
// Shows specific arrows fiven as parameters in an array
function activateControlFlow(arrayControl) {
$.each(arrayControl, function(key, selector){
$(selector).css({color:'#FFF', cursor: 'pointer'});
});
}
var scene4 = document.getElementById('scene4');
var parallax = new Parallax(scene4);
var scene5 = document.getElementById('scene5');
var parallax = new Parallax(scene5);
var scene6 = document.getElementById('scene6');
var parallax = new Parallax(scene6);
var scene8 = document.getElementById('scene8');
var parallax = new Parallax(scene8);
var scene9 = document.getElementById('scene9');
var parallax = new Parallax(scene9);
var scene10 = document.getElementById('scene10');
var parallax = new Parallax(scene10);
});
});
$(document).ready(function() {
var all = $("#slider-view");
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
$(all).css('height', window.innerHeight);
$(all).css('width', window.innerWidth);
// Assigns the container that has all the sections that will be scrolled horizontally
var sliderH = $('.nav-h');
var sliderVMiddle = $('.nav-v-middle');
var sliderVLast = $('.nav-v-last');
// Gets the number of slides of the horizontal slider
var sliderCountH = $('.nav-h').children().size();
var sliderCountVMiddle = $('.nav-v-middle').children().size();
var sliderCountVLast = $('.nav-v-last').children().size();
// Sets the properties of the arrows that have the events
setCssRect(sliderH, 'w', winWidth);
setCssRect(sliderH, 'h', winHeight);
setCssRect(sliderVMiddle, 'w', winWidth);
setCssRect(sliderVMiddle, 'h', winHeight);
setCssRect(sliderVLast, 'w', winWidth);
setCssRect(sliderVLast, 'h', winHeight);
// sets css size properties on the jQuery element.
function setCssRect(elt, property, value) {
if(property=='w') {
$('> div',elt).css('width', value);
}
else {$('> div',elt).css('height', value);}
}
// Gets the number of Horizontal or Vertical slide
var viewWidth = sliderCountH * winWidth;
var heightVMiddle = sliderCountVMiddle * winHeight;
var heightVLast = sliderCountVLast * winHeight;
// Sets the width and height for the Horizontal and Vertical slides
$('.nav-h').css('width', viewWidth);
$('.nav-v-middle').css('height', heightVMiddle);
$('.nav-v-last').css('height', heightVLast);
var isMobile = {
Android: function() { return navigator.userAgent.match(/Android/i); },
BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); },
iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); },
Opera: function() { return navigator.userAgent.match(/Opera Mini/i); },
Windows: function() { return navigator.userAgent.match(/IEMobile/i); },
any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); }
};
if ( isMobile.any() ) {
$('a#prevh').toggle();
$('a#nexth').toggle();
$('a#prevv').toggle();
$('a#nextv').toggle();
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
// actions for the swiperight
$(sliderH).hammer({prevent_default:true}).on('swiperight', function() {
actionHorizontalAnimation(0, '+', '+');
});
// Actions for the swipeLeft
$(sliderH).hammer({prevent_default:true}).on('swipeleft', function() {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
// Actions for the swipeUp
$(sliderH).hammer({prevent_default:true}).on('swipedown', function() {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
// Actions for the swipeDown
$(sliderH).hammer({prevent_default:true}).on('swipeup', function() {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
else {
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
$('a#prevh').on('click', function(event) {
actionHorizontalAnimation(0, '+', '+');
});
$('a#nexth').on('click', function(event) {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
$('a#prevv').on('click', function(event) {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
$('a#nextv').on('click', function(event) {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
// Onclick horizontal movement
function actionHorizontalAnimation(sliderPosition, orientation, shift) {
if(verticalIndexMiddle!==0) {
verticalAnimation(sliderVMiddle, '+', (winHeight*verticalIndexMiddle))
verticalIndexMiddle = 0;
}
if(verticalIndexLast!==0) {
verticalAnimation(sliderVLast, '+', (winHeight*verticalIndexLast))
verticalIndexLast = 0;
}
if(horizontalIndex!==sliderPosition) {
horizontalAnimation(sliderH, shift, winWidth);
if(orientation==='-'){horizontalIndex+=1;}else{horizontalIndex-=1;}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// OnClick vertical movement
function actionVerticalAnimation(middleSlidePosition, lastSlidePosition, orientation) {
if(horizontalIndex==1) {
if(verticalIndexMiddle!==middleSlidePosition) {
verticalAnimation(sliderVMiddle, orientation, winHeight);
if(orientation==='-'){verticalIndexMiddle+=1;} else {verticalIndexMiddle-=1;}
}
}
else if (horizontalIndex==2) {
if(verticalIndexLast!==lastSlidePosition) {
verticalAnimation(sliderVLast, orientation, winHeight)
if(orientation==='-'){verticalIndexLast+=1;} else {verticalIndexLast-=1;}
}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// animation for vertical slide
function verticalAnimation(slider, action, size) {
$('> div', slider).animate({
top: action+'=' + size
}, 600);
}
// animation for horizontal slide
function horizontalAnimation(slider, action, size) {
$('> div', slider).animate({
left: action+'=' + size
}, 600);
}
// Set hides or shows the arrows for the navigation
function findSlidePosition(h1, v1, v2) {
$('.nav-btns div').css('border-color', '#706E6D');
resetObjectStyle();
if(h1==0 && v1==0 && v2==0) {
$('.nav-home').css('border-color','#FFF');
activateControlFlow(['#nexth']);
}
else if(h1==1 && v1==0 && v2==0) {
$('.nav-middle-slide1').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv']);
}
else if(h1==1 && v1>=1 && v1<=8 && v2==0) {
var test = '.nav-middle-slide'+ (v1+1);
$(test).css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv', '#prevv']);
}
else if(h1==1 && v1==9 && v2==0) {
$('.nav-middle-slide10').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#prevv']);
}
else if(h1==2 && v1==0 && v2==0) {
$('.nav-last-slide1').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv']);
}
else if(h1==2 && v1==0 && (v2==1 || v2==2)) {
$('.nav-last-slide2').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv', '#prevv']);
}
else if(h1==2 && v1==0 && v2==3) {
$('.nav-last-slide4').css('border-color','#FFF');
activateControlFlow(['#prevh', '#prevv']);
}
}
// Hides all the arrows
function resetObjectStyle() {
$('a.control-flow').css({color:'transparent', cursor: 'auto'});
}
// Shows specific arrows fiven as parameters in an array
function activateControlFlow(arrayControl) {
$.each(arrayControl, function(key, selector){
$(selector).css({color:'#FFF', cursor: 'pointer'});
});
}
var scene4 = document.getElementById('scene4');
var parallax = new Parallax(scene4);
var scene5 = document.getElementById('scene5');
var parallax = new Parallax(scene5);
var scene6 = document.getElementById('scene6');
var parallax = new Parallax(scene6);
var scene8 = document.getElementById('scene8');
var parallax = new Parallax(scene8);
var scene9 = document.getElementById('scene9');
var parallax = new Parallax(scene9);
var scene10 = document.getElementById('scene10');
var parallax = new Parallax(scene10);
});
$(document).ready(function() {
var all = $("#slider-view");
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
$(all).css('height', window.innerHeight);
$(all).css('width', window.innerWidth);
// Assigns the container that has all the sections that will be scrolled horizontally
var sliderH = $('.nav-h');
var sliderVMiddle = $('.nav-v-middle');
var sliderVLast = $('.nav-v-last');
// Gets the number of slides of the horizontal slider
var sliderCountH = $('.nav-h').children().size();
var sliderCountVMiddle = $('.nav-v-middle').children().size();
var sliderCountVLast = $('.nav-v-last').children().size();
// Sets the properties of the arrows that have the events
setCssRect(sliderH, 'w', winWidth);
setCssRect(sliderH, 'h', winHeight);
setCssRect(sliderVMiddle, 'w', winWidth);
setCssRect(sliderVMiddle, 'h', winHeight);
setCssRect(sliderVLast, 'w', winWidth);
setCssRect(sliderVLast, 'h', winHeight);
// sets css size properties on the jQuery element.
function setCssRect(elt, property, value) {
if(property=='w') {
$('> div',elt).css('width', value);
}
else {$('> div',elt).css('height', value);}
}
// Gets the number of Horizontal or Vertical slide
var viewWidth = sliderCountH * winWidth;
var heightVMiddle = sliderCountVMiddle * winHeight;
var heightVLast = sliderCountVLast * winHeight;
// Sets the width and height for the Horizontal and Vertical slides
$('.nav-h').css('width', viewWidth);
$('.nav-v-middle').css('height', heightVMiddle);
$('.nav-v-last').css('height', heightVLast);
var isMobile = {
Android: function() { return navigator.userAgent.match(/Android/i); },
BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); },
iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); },
Opera: function() { return navigator.userAgent.match(/Opera Mini/i); },
Windows: function() { return navigator.userAgent.match(/IEMobile/i); },
any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); }
};
if ( isMobile.any() ) {
$('a#prevh').toggle();
$('a#nexth').toggle();
$('a#prevv').toggle();
$('a#nextv').toggle();
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
// actions for the swiperight
$(sliderH).hammer({prevent_default:true}).on('swiperight', function() {
actionHorizontalAnimation(0, '+', '+');
});
// Actions for the swipeLeft
$(sliderH).hammer({prevent_default:true}).on('swipeleft', function() {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
// Actions for the swipeUp
$(sliderH).hammer({prevent_default:true}).on('swipedown', function() {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
// Actions for the swipeDown
$(sliderH).hammer({prevent_default:true}).on('swipeup', function() {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
else {
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
$('a#prevh').on('click', function(event) {
actionHorizontalAnimation(0, '+', '+');
});
$('a#nexth').on('click', function(event) {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
$('a#prevv').on('click', function(event) {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
$('a#nextv').on('click', function(event) {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
// Onclick horizontal movement
function actionHorizontalAnimation(sliderPosition, orientation, shift) {
if(verticalIndexMiddle!==0) {
verticalAnimation(sliderVMiddle, '+', (winHeight*verticalIndexMiddle))
verticalIndexMiddle = 0;
}
if(verticalIndexLast!==0) {
verticalAnimation(sliderVLast, '+', (winHeight*verticalIndexLast))
verticalIndexLast = 0;
}
if(horizontalIndex!==sliderPosition) {
horizontalAnimation(sliderH, shift, winWidth);
if(orientation==='-'){horizontalIndex+=1;}else{horizontalIndex-=1;}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// OnClick vertical movement
function actionVerticalAnimation(middleSlidePosition, lastSlidePosition, orientation) {
if(horizontalIndex==1) {
if(verticalIndexMiddle!==middleSlidePosition) {
verticalAnimation(sliderVMiddle, orientation, winHeight);
if(orientation==='-'){verticalIndexMiddle+=1;} else {verticalIndexMiddle-=1;}
}
} else if (horizontalIndex==2) {
if(verticalIndexLast!==lastSlidePosition) {
verticalAnimation(sliderVLast, orientation, winHeight)
if(orientation==='-'){verticalIndexLast+=1;} else {verticalIndexLast-=1;}
}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// animation for vertical slide
function verticalAnimation(slider, action, size) {
$('> div', slider).animate({
top: action+'=' + size
}, 600);
}
// animation for horizontal slide
function horizontalAnimation(slider, action, size) {
$('> div', slider).animate({
left: action+'=' + size
}, 600);
}
// Set hides or shows the arrows for the navigation
function findSlidePosition(h1, v1, v2) {
$('.nav-btns div').css('border-color', '#706E6D');
resetObjectStyle();
if(h1==0 && v1==0 && v2==0) {
$('.nav-home').css('border-color','#FFF');
activateControlFlow(['#nexth']);
}
else if(h1==1 && v1==0 && v2==0) {
$('.nav-middle-slide1').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv']);
}
else if(h1==1 && v1>=1 && v1<=8 && v2==0) {
var test = '.nav-middle-slide'+ (v1+1);
$(test).css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv', '#prevv']);
}
else if(h1==1 && v1==9 && v2==0) {
$('.nav-middle-slide10').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#prevv']);
}
else if(h1==2 && v1==0 && v2==0) {
$('.nav-last-slide1').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv']);
}
else if(h1==2 && v1==0 && (v2==1 || v2==2)) {
$('.nav-last-slide2').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv', '#prevv']);
}
else if(h1==2 && v1==0 && v2==3) {
$('.nav-last-slide4').css('border-color','#FFF');
activateControlFlow(['#prevh', '#prevv']);
}
}
// Hides all the arrows
function resetObjectStyle() {
$('a.control-flow').css({color:'transparent', cursor: 'auto'});
}
// Shows specific arrows fiven as parameters in an array
function activateControlFlow(arrayControl) {
$.each(arrayControl, function(key, selector){
$(selector).css({color:'#FFF', cursor: 'pointer'});
});
}
var scene4 = document.getElementById('scene4');
var parallax = new Parallax(scene4);
var scene5 = document.getElementById('scene5');
var parallax = new Parallax(scene5);
var scene6 = document.getElementById('scene6');
var parallax = new Parallax(scene6);
var scene8 = document.getElementById('scene8');
var parallax = new Parallax(scene8);
var scene9 = document.getElementById('scene9');
var parallax = new Parallax(scene9);
var scene10 = document.getElementById('scene10');
var parallax = new Parallax(scene10);
});
JQuery carousel code review
So here is my code. I would like feedback on things I can improve. If you want to see the full example on action here is the link. And here is the js code
$(document).ready(function() {
var all = $("#slider-view");
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
$(all).css('height', window.innerHeight);
$(all).css('width', window.innerWidth);
// Assigns the container that has all the sections that will be scrolled horizontally
var sliderH = $('.nav-h');
var sliderVMiddle = $('.nav-v-middle');
var sliderVLast = $('.nav-v-last');
// Gets the number of slides of the horizontal slider
var sliderCountH = $('.nav-h').children().size();
var sliderCountVMiddle = $('.nav-v-middle').children().size();
var sliderCountVLast = $('.nav-v-last').children().size();
// Sets the properties of the arrows that have the events
setCssRect(sliderH, 'w', winWidth);
setCssRect(sliderH, 'h', winHeight);
setCssRect(sliderVMiddle, 'w', winWidth);
setCssRect(sliderVMiddle, 'h', winHeight);
setCssRect(sliderVLast, 'w', winWidth);
setCssRect(sliderVLast, 'h', winHeight);
// sets css size properties on the jQuery element.
function setCssRect(elt, property, value) {
if(property=='w') {
$('> div',elt).css('width', value);
}
else {$('> div',elt).css('height', value);}
}
// Gets the number of Horizontal or Vertical slide
var viewWidth = sliderCountH * winWidth;
var heightVMiddle = sliderCountVMiddle * winHeight;
var heightVLast = sliderCountVLast * winHeight;
// Sets the width and height for the Horizontal and Vertical slides
$('.nav-h').css('width', viewWidth);
$('.nav-v-middle').css('height', heightVMiddle);
$('.nav-v-last').css('height', heightVLast);
var isMobile = {
Android: function() { return navigator.userAgent.match(/Android/i); },
BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); },
iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); },
Opera: function() { return navigator.userAgent.match(/Opera Mini/i); },
Windows: function() { return navigator.userAgent.match(/IEMobile/i); },
any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); }
};
if ( isMobile.any() ) {
$('a#prevh').toggle();
$('a#nexth').toggle();
$('a#prevv').toggle();
$('a#nextv').toggle();
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
// actions for the swiperight
$(sliderH).hammer({prevent_default:true}).on('swiperight', function() {
actionHorizontalAnimation(0, '+', '+');
});
// Actions for the swipeLeft
$(sliderH).hammer({prevent_default:true}).on('swipeleft', function() {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
// Actions for the swipeUp
$(sliderH).hammer({prevent_default:true}).on('swipedown', function() {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
// Actions for the swipeDown
$(sliderH).hammer({prevent_default:true}).on('swipeup', function() {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
else {
var horizontalIndex = 0;
var verticalIndexMiddle = 0;
var verticalIndexLast = 0;
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
$('a#prevh').on('click', function(event) {
actionHorizontalAnimation(0, '+', '+');
});
$('a#nexth').on('click', function(event) {
actionHorizontalAnimation((sliderCountH-1), '-', '-');
});
$('a#prevv').on('click', function(event) {
actionVerticalAnimation(0, sliderCountVLast, '+');
});
$('a#nextv').on('click', function(event) {
actionVerticalAnimation((sliderCountVMiddle-1), (sliderCountVLast-1), '-');
});
}
// Onclick horizontal movement
function actionHorizontalAnimation(sliderPosition, orientation, shift) {
if(verticalIndexMiddle!==0) {
verticalAnimation(sliderVMiddle, '+', (winHeight*verticalIndexMiddle))
verticalIndexMiddle = 0;
}
if(verticalIndexLast!==0) {
verticalAnimation(sliderVLast, '+', (winHeight*verticalIndexLast))
verticalIndexLast = 0;
}
if(horizontalIndex!==sliderPosition) {
horizontalAnimation(sliderH, shift, winWidth);
if(orientation==='-'){horizontalIndex+=1;}else{horizontalIndex-=1;}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// OnClick vertical movement
function actionVerticalAnimation(middleSlidePosition, lastSlidePosition, orientation) {
if(horizontalIndex==1) {
if(verticalIndexMiddle!==middleSlidePosition) {
verticalAnimation(sliderVMiddle, orientation, winHeight);
if(orientation==='-'){verticalIndexMiddle+=1;} else {verticalIndexMiddle-=1;}
}
}
else if (horizontalIndex==2) {
if(verticalIndexLast!==lastSlidePosition) {
verticalAnimation(sliderVLast, orientation, winHeight)
if(orientation==='-'){verticalIndexLast+=1;} else {verticalIndexLast-=1;}
}
}
findSlidePosition(horizontalIndex, verticalIndexMiddle, verticalIndexLast);
}
// animation for vertical slide
function verticalAnimation(slider, action, size) {
$('> div', slider).animate({
top: action+'=' + size
}, 600);
}
// animation for horizontal slide
function horizontalAnimation(slider, action, size) {
$('> div', slider).animate({
left: action+'=' + size
}, 600);
}
// Set hides or shows the arrows for the navigation
function findSlidePosition(h1, v1, v2) {
$('.nav-btns div').css('border-color', '#706E6D');
resetObjectStyle();
if(h1==0 && v1==0 && v2==0) {
$('.nav-home').css('border-color','#FFF');
activateControlFlow(['#nexth']);
}
else if(h1==1 && v1==0 && v2==0) {
$('.nav-middle-slide1').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv']);
}
else if(h1==1 && v1>=1 && v1<=8 && v2==0) {
var test = '.nav-middle-slide'+ (v1+1);
$(test).css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#nextv', '#prevv']);
}
else if(h1==1 && v1==9 && v2==0) {
$('.nav-middle-slide10').css('border-color','#FFF');
activateControlFlow(['#nexth', '#prevh', '#prevv']);
}
else if(h1==2 && v1==0 && v2==0) {
$('.nav-last-slide1').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv']);
}
else if(h1==2 && v1==0 && (v2==1 || v2==2)) {
$('.nav-last-slide2').css('border-color','#FFF');
activateControlFlow(['#prevh', '#nextv', '#prevv']);
}
else if(h1==2 && v1==0 && v2==3) {
$('.nav-last-slide4').css('border-color','#FFF');
activateControlFlow(['#prevh', '#prevv']);
}
}
// Hides all the arrows
function resetObjectStyle() {
$('a.control-flow').css({color:'transparent', cursor: 'auto'});
}
// Shows specific arrows fiven as parameters in an array
function activateControlFlow(arrayControl) {
$.each(arrayControl, function(key, selector){
$(selector).css({color:'#FFF', cursor: 'pointer'});
});
}
var scene4 = document.getElementById('scene4');
var parallax = new Parallax(scene4);
var scene5 = document.getElementById('scene5');
var parallax = new Parallax(scene5);
var scene6 = document.getElementById('scene6');
var parallax = new Parallax(scene6);
var scene8 = document.getElementById('scene8');
var parallax = new Parallax(scene8);
var scene9 = document.getElementById('scene9');
var parallax = new Parallax(scene9);
var scene10 = document.getElementById('scene10');
var parallax = new Parallax(scene10);
});
default