Skip to content

Commit

Permalink
some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPogorelov committed Apr 28, 2016
1 parent d494beb commit 7902905
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 372 deletions.
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ <h3 class="type-1">AATSU pop-up 3</h3>

<script src="../libs/jquery/dist/jquery.min.js"></script>
<script src="../libs/jquery.browser/dist/jquery.browser.min.js"></script>
<script src="../libs/picturefill/dist/picturefill.min.js"></script>
<!-- <script src="../libs/picturefill/dist/picturefill.min.js"></script> -->
<!-- <script src="../libs/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"></script> -->
<script src="js/scrollpage.js"></script>
<script src="js/main.js"></script>
Expand Down
43 changes: 18 additions & 25 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ $(document).on('ready', function () {
var scrollStarted = false,
blurStatus = 0,
blurMax = 12,
max = 50;
max = 20;

if ($.browser.platform === "win") {

Expand Down Expand Up @@ -777,18 +777,6 @@ $(document).on('ready', function () {

if ( e.target.nodeName.toLowerCase() === 'img' ) {

function closeModal () {

$tint.removeClass('active');
$clone.css( stylesStack ).one(transitionPrefix, function () {

$clone.remove();
$tint.remove();

});

}

var $body = $('body'),
$modal = $(this),
$target = $(e.target),
Expand All @@ -798,6 +786,18 @@ $(document).on('ready', function () {
origWidth = $target.width(),
origHeight = $target.height();

var closeModal = function () {

$tint.removeClass('active');
$clone.css( stylesStack ).one(transitionPrefix, function () {

$clone.off().remove();
$tint.off().remove();

});

};

var stylesStack = {
'position': 'fixed',
'z-index': '20',
Expand All @@ -810,6 +810,7 @@ $(document).on('ready', function () {
},
$tint = $('<div>')
.addClass('tint')
.one('DOMMouseScroll wheel mousewheel touchstart click', closeModal)
.appendTo( $body );

var stylesTarget = {
Expand All @@ -822,28 +823,20 @@ $(document).on('ready', function () {
'width': e.target.naturalWidth
};

if (e.target.naturalWidth > winWidth - 20) {
if (e.target.naturalWidth > winWidth / 1.5) {

var ratio = e.target.naturalWidth / e.target.naturalHeight;
stylesTarget.width = winWidth - 20;
stylesTarget.height = winWidth / ratio;
stylesTarget.width = winWidth / 1.5;
stylesTarget.height = stylesTarget.width / ratio;

}

$clone
.on('click', function (e) {

e.stopPropagation();

})
.one('DOMMouseScroll wheel mousewheel touchstart', closeModal)
.addClass( 'modal-image' )
.css( stylesStack )
.one('DOMMouseScroll wheel mousewheel touchstart click', closeModal)
.appendTo( $body );

// $tint.one('mousedown DOMMouseScroll wheel mousewheel', closeModal);
$tint.one('mousedown', closeModal);

setTimeout(function () {

$clone.css( stylesTarget );
Expand Down
64 changes: 27 additions & 37 deletions src/js/scrollpage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// crossbrowser
/* GLOBAL */
var animationPrefix = (function () {
var t,
el = document.createElement("fakeelement"),
Expand Down Expand Up @@ -41,26 +41,20 @@ var animationPrefix = (function () {

}

})();
})(),
pagesState = {},
touchState = {
touchStart: {},
touchEnd: {}
},
windowWidth = $(window).width(),
windowHeight = $(window).height(),
cacheDom = {};

// htmlBody = 'body';
if ( jQuery.browser.mobile ) {
$('body').addClass('mobile');
}

/* GLOBAL */
// var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/);
// var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
// if (isTouchDevice || isTouch) {
// // $('body').css('overflow', 'auto');
// }
// isTouch = false;

var pagesState = {},
touchState = {
touchStart: {},
touchEnd: {}
};

pagesState.lastScrollTime = new Date().getTime() - 1000;

Expand All @@ -72,15 +66,23 @@ var pagesAnimation = (function () {
$socials = $('.socials-holder'),
plg = function (id) {

if ( id > 3 ) {
if ( id > 0 ) {

$foreground.hide();

} else {

$foreground.show();

}

if ( id > 3 ) {

$socials.removeClass('deactive');

} else {

$socials.addClass('deactive');
$foreground.show();

}

Expand All @@ -90,10 +92,6 @@ var pagesAnimation = (function () {

})();

var windowWidth = $(window).width();
var windowHeight = $(window).height();
var cacheDom = {};

$(window).load(function(){

scrollPages.init();
Expand All @@ -109,14 +107,12 @@ cacheDom.$horizontal = cacheDom.$horizontalViewport.find(' > .full-height');
cacheDom.$menu = $('#main-navigation');

/* IF RESIZE */
$(window).resize(function () {
$(window).on('resize', function () {

windowWidth = $(window).width();
windowHeight = $(window).height();

});

$(window).on('mousewheel', function (e) {
}).on('mousewheel', function (e) {

e.preventDefault();
e.stopPropagation();
Expand All @@ -139,9 +135,7 @@ $(window).on('mousewheel', function (e) {

pagesState.lastScrollTime = new Date().getTime();

});

$(window).on('DOMMouseScroll wheel', function (e) {
}).on('DOMMouseScroll wheel', function (e) {

e.preventDefault();
e.stopPropagation();
Expand Down Expand Up @@ -169,9 +163,7 @@ $('body').on('touchstart', function (e) {

touchState.touchStart.timeStamp = e.timeStamp;

});

$('body').on('touchmove', function (e) {
}).on('touchmove', function (e) {

e.preventDefault();
touchState.touchEnd.xPos = e.originalEvent.touches[0].clientX;
Expand All @@ -184,9 +176,7 @@ $('body').on('touchmove', function (e) {
touchState.touchStart.yPos = touchState.touchEnd.yPos;
}

});

$('body').on('touchend', function (e) {
}).on('touchend', function (e) {
if (pagesState.animatedBool) {
return;
}
Expand Down Expand Up @@ -346,7 +336,7 @@ var scrollPages = (function () {

this.blockScroll(true);

console.log(top)
// console.log(top)
cacheDom.$verticalViewport
.off(transitionPrefix)
.css({
Expand Down Expand Up @@ -468,7 +458,7 @@ console.log(top)

}

}, 500);
}, 300);

},
blockScroll: function ( boolean, lock ) {
Expand Down
Loading

0 comments on commit 7902905

Please sign in to comment.