Created
March 26, 2015 09:48
-
-
Save victorpavlenko/132d03e73e019ae7182a to your computer and use it in GitHub Desktop.
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 superScrollMaxY; | |
var disableAllScrollEffects = false; | |
var refreshWindowHeight = function () { | |
superScrollMaxY = document.body.scrollHeight - window.innerHeight; | |
}; | |
// делает из элемента супер-скролл | |
var makeSuperScroll = function (elem, elTop, scrollElem) { | |
var w; | |
var scrollTop; | |
var largeScroll2; | |
var elemTop; | |
var elemPosition; | |
var elemHeight; | |
var setParams = function () { | |
var $superScrollBody = null; | |
w = $(window); | |
scrollTop = w.scrollTop(); | |
superScrollMaxY = document.body.scrollHeight - window.innerHeight; | |
elemHeight = elem.height(); | |
$superScrollBody = $("[superscroll-body]"); | |
$superScrollBody = !!$superScrollBody.length ? $superScrollBody : $('[data-superscroll-body]'); | |
elemTop = elTop; | |
if (!elemTop && !!$superScrollBody.length) { | |
elemTop = $superScrollBody.css("padding-top").substring(0, $superScrollBody.css("padding-top").length - 2) | |
} | |
//elemTop = elTop ? elTop : $("[superscroll-body]").length ? $("[superscroll-body]").css("padding-top").substring(0, $("[superscroll-body]").css("padding-top").length - 2) : $("[data-superscroll-body]").css("padding-top").substring(0, $("[data-superscroll-body]").css("padding-top").length - 2); | |
elemPosition = elem.css("position"); | |
}; | |
var goScroll = function () { | |
if (disableAllScrollEffects) return; | |
if (scrollElem) { | |
scrollTop = scrollElem.scrollTop(); | |
elem.css({"position": "fixed", "z-index": "1000", "height": w.height() - elemTop + "px", "overflow": "hidden"}); | |
elem.setClass("scrollable"); | |
scrollElem.find(".fancybox-close").css({"top": scrollTop + 20, "z-index": "99999"}); | |
elem.scrollTop(elem.scrollTop() + (scrollTop - largeScroll2)); | |
largeScroll2 = scrollTop; | |
} else if ((window.scrollY < superScrollMaxY) && (window.scrollY >= 0)) { | |
superScrollMaxY = document.body.scrollHeight - window.innerHeight; | |
scrollTop = w.scrollTop(); | |
elem.css({"position": "fixed", "z-index": "1000", "height": w.height() - elemTop + "px", "overflow": "hidden"}); | |
elem.setClass("scrollable"); | |
elem.scrollTop(elem.scrollTop() + (scrollTop - largeScroll2)); | |
largeScroll2 = scrollTop; | |
} | |
}; | |
setParams(); | |
goScroll(); | |
w.resize(function () { | |
setParams(); | |
goScroll(); | |
}); | |
w.on('scroll', function () { | |
goScroll(); | |
}); | |
if (scrollElem) { | |
scrollElem.on('scroll', function () { | |
goScroll(); | |
}); | |
} | |
}; | |
// делаем шапку профиля | |
var makeProfileHead = function (elem, menu) { | |
var w; | |
var scrollTop; | |
var setParams = function () { | |
w = $(window); | |
scrollTop = w.scrollTop(); | |
}; | |
var goScroll = function () { | |
if (disableAllScrollEffects) return; | |
scrollTop = w.scrollTop(); | |
if (scrollTop > 261) { | |
$("[superscroll-body], [data-superscroll-body]").css("padding-top", "409px"); | |
$(".user-box", elem).css("top", 0); | |
elem.setClass("fixed-profile-head"); | |
menu.setClass("fixed-submenu"); | |
$(".user-box", elem).setClass("fixed-profile-person"); | |
} else { | |
$("[superscroll-body], [data-superscroll-body]").css("padding-top", "0px"); | |
elem.unsetClass("fixed-profile-head"); | |
menu.unsetClass("fixed-submenu"); | |
$(".user-box", elem).unsetClass("fixed-profile-person"); | |
} | |
}; | |
setParams(); | |
goScroll(); | |
w.resize(function () { | |
setParams(); | |
goScroll(); | |
}); | |
w.scroll(function () { | |
goScroll(); | |
}); | |
}; | |
// делаем шапку на главной | |
var makeMainHead = function (elem, menu, button) { | |
var w; | |
var scrollTop; | |
var logosVisible = false; | |
var setParams = function () { | |
w = $(window); | |
scrollTop = w.scrollTop(); | |
}; | |
var goScroll = function () { | |
var $slogan = $(".slogan", menu); | |
if (disableAllScrollEffects) return; | |
scrollTop = w.scrollTop(); | |
if(scrollTop > 75){ | |
console.log(2) | |
$('.items-catalog').on('hover', function(){ | |
$(this).find('.drop-holder').toggleClass('show'); | |
$(this).find('.category').addClass('active'); | |
}); | |
}else{ | |
console.log(1) | |
$('.items-catalog').on('hover', function(){ | |
$($(document).find('.category')[1]).toggleClass('active'); | |
}); | |
} | |
console.log(scrollTop); | |
if (scrollTop > 20 ) { | |
elem.setClass("fixed-head"); | |
$(".header-aside").css({top: 15}); | |
$(".header-aside .login > .userpic img", elem).css({width: 35, height: 35}); | |
$(".header-aside .login > .userpic .avatar-overlay", elem).css({width: 35, height: 35}); | |
} else { | |
elem.unsetClass("fixed-head"); | |
$(".header-aside").css({top: 19}); | |
$(".header-aside .login > .userpic img", elem).css({width: 40, height: 40}); | |
$(".header-aside .login > .userpic .avatar-overlay", elem).css({width: 40, height: 40}); | |
} | |
if (scrollTop > 60) { | |
$('.nav') | |
.css({ | |
position: 'fixed', | |
top: '0px' | |
}); | |
} else { | |
$('.nav') | |
.css({ | |
position: 'relative', | |
top: '0' | |
}); | |
} | |
if (scrollTop > 68) { | |
elem.setClass("fixed-head-border"); | |
$("[superscroll-body], [data-superscroll-body]").css("padding-top", "132px"); | |
elem.css({"top": "-900px", "position": "absolute"}); | |
menu.setClass("fixed-menu").css({boxShadow : "0px 2px 6px 0px rgba(0, 0, 0, 0.1)"}); | |
button.setClass("btn-yut-club-scrolled"); | |
if (!logosVisible) { | |
$(".logo", menu).css("left", "-500px").stop().animate({left: 40}, 200, function(){ | |
if (!!$slogan.length) { | |
$(".slogan", menu).stop().animate({opacity: 1}, 500); | |
} | |
}); | |
$(".left-logo-holder", menu).css("left", "-500px").stop().animate({left: 40}, {duration: 200}); | |
} | |
logosVisible = true; | |
} else { | |
elem.unsetClass("fixed-head-border"); | |
$("[superscroll-body], [data-superscroll-body]").css("padding-top", "0px"); | |
elem.css({"top": "0px", "position": "relative"}); | |
menu.unsetClass("fixed-menu").css({boxShadow: ''}); | |
button.unsetClass("btn-yut-club-scrolled"); | |
if (logosVisible) { | |
if (!!$slogan.length) { | |
$(".slogan").stop().animate({opacity: 0}, 200, function(){ | |
$(".logo", menu).stop().animate({left: -500}, 200); | |
$(".left-logo-holder", menu).stop().animate({left: -500}, {duration: 200}); | |
}); | |
} else { | |
$(".logo", menu).stop().animate({left: -500}, 200); | |
$(".left-logo-holder", menu).stop().animate({left: -500}, {duration: 200}); | |
} | |
} | |
logosVisible = false; | |
} | |
}; | |
setParams(); | |
goScroll(); | |
w.resize(function () { | |
setParams(); | |
goScroll(); | |
}); | |
w.scroll(function () { | |
goScroll(); | |
}); | |
}; | |
// Делаем главную правую колонку | |
var makeMainSidebar = function (elem) { | |
var w; | |
var scrollTop; | |
var elemTop; | |
var setParams = function () { | |
w = $(window); | |
scrollTop = w.scrollTop(); | |
elemTop = elem.offset().top; | |
}; | |
var goScroll = function () { | |
if (disableAllScrollEffects) return; | |
scrollTop = w.scrollTop(); | |
if (scrollTop > (elemTop + elem.height() - w.height())) { | |
elem.setClass("fixed-sidebar"); | |
} else { | |
elem.unsetClass("fixed-sidebar"); | |
} | |
}; | |
setParams(); | |
goScroll(); | |
/*w.resize(function () { | |
setParams(); | |
goScroll(); | |
});*/ | |
w.scroll(function () { | |
goScroll(); | |
}); | |
}; | |
// делаем промоблок в странице сета | |
var makePromoBlock = function (elem, menu) { | |
var scrollTop, w, | |
elemTop = menu.outerHeight(), | |
elemHeight = elem.outerHeight(), | |
elemTopMargin = elem.css("margin-top").slice(0, -2) * 1, | |
animatedTitle = false, | |
superPadding = $("[data-superscroll-body]").css("padding-top").slice(0, -2) * 1; | |
var scrollMaxY; | |
var largeScroll2; | |
var sidebar = $("#setSidebar"); | |
var setParams = function () { | |
w = $(window); | |
scrollTop = w.scrollTop(); | |
scrollMaxY = document.body.scrollHeight - window.innerHeight; | |
}; | |
var goScroll = function () { | |
$(".visual").css({ | |
'bottom': 400 + scrollTop/2.2 | |
}); | |
if (disableAllScrollEffects) return; | |
scrollTop = w.scrollTop(); | |
if (elem.outerHeight() > elemHeight) { | |
elemHeight = elem.height() | |
} | |
if (scrollTop > (elemHeight - elemTop + 22)) { | |
elem.setClass("fixed-promo"); | |
elem.css("top", elemTop); | |
if (!animatedTitle) { | |
$(".fixed-title", elem).css("display", "block").animate({bottom: 0}, {duration: 200}); | |
$("#menu").setClass("menu-fixed-set"); | |
animatedTitle = true; | |
} | |
$("[data-superscroll-body]").css("padding-top", superPadding + elemHeight + 22); | |
if ((window.scrollY < scrollMaxY) && (window.scrollY >= 0)) { | |
sidebar.css({"position": "fixed", "z-index": "1000", "height": w.height() - elem.height() - elemTop + "px", "overflow": "hidden"}); | |
sidebar.setClass("scrollable"); | |
sidebar.scrollTop(sidebar.scrollTop() + (scrollTop - largeScroll2)); | |
} | |
} else { | |
if (animatedTitle) { | |
$("#menu").unsetClass("menu-fixed-set"); | |
$(".fixed-title", elem).css({"display": "none", "bottom": "-90px"}); | |
animatedTitle = false; | |
} | |
elem.unsetClass("fixed-promo"); | |
elem.css("top", "auto"); | |
$("[data-superscroll-body]").css("padding-top", superPadding); | |
if ((window.scrollY < scrollMaxY) && (window.scrollY >= 0)) { | |
sidebar.css({"position": "relative", "height": "auto", "overflow": "visible"}); | |
sidebar.unsetClass("scrollable"); | |
} | |
} | |
largeScroll2 = scrollTop; | |
}; | |
setParams(); | |
goScroll(); | |
w.resize(function () { | |
setParams(); | |
goScroll(); | |
}); | |
w.scroll(function () { | |
goScroll(); | |
}); | |
}; | |
$(document).ready(function () { | |
// подключаем супер-скролл для всех элементов с этим атрибутом | |
$("[superscroll], [data-superscroll]").each(function () { | |
var elem = $(this); | |
makeSuperScroll(elem); | |
}); | |
if ($("#profileHeader").length && $("#profileMenu").length) { | |
makeProfileHead($("#profileHeader"), $("#profileMenu")); | |
} | |
if ($("#mainHeader").length && $("#mainMenu").length) { | |
makeMainHead($("#mainHeader"), $("#mainMenu"), $("#button")); | |
} | |
if ($("#header").length && $("#mainMenu").length && !$('#profile-page').length && !$('#all_posts-page').length) { | |
makeMainHead($("#header"), $("#mainMenu"), $("#button")); | |
} | |
if ($("#promoBlock").length) { | |
makePromoBlock($("#promoBlock"), $("#menu")); | |
} | |
if ($("#popupItem").length && $("#popupItem").hasClass("open")) { | |
makePopupItem($("#popupItem"), $("#popupItemNav")); | |
} | |
function scrollShadow(elem, shadowTo) { | |
if( $(elem).length ) { | |
$(window).on('scroll', function() { | |
if($(window).scrollTop() > 59) { | |
$(shadowTo).css({boxShadow: 'rgba(0, 0, 0, 0.0980392) 0px 2px 6px 0px'}); | |
} else { | |
$(shadowTo).css({boxShadow: ''}); | |
} | |
}); | |
} | |
} | |
scrollShadow('.catalog-page', '#submenu'); | |
scrollShadow('.basket-page', '.steps-panel'); | |
scrollShadow('#all_posts-page', '#submenu'); | |
$('.items-catalog').on('click', function(){ | |
$('.category').toggleClass('active'); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment