Created
February 14, 2019 22:06
-
-
Save xTCry/259bec97d357e6a6c74ddd4046ab2b0e to your computer and use it in GitHub Desktop.
MH. Menu, Sidebar, ScrollButtonTODO
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
$(document).ready(function() { | |
// Open Landingpage in new tab | |
$('a[href*="/lp/"]').attr('target','_blank'); | |
}); | |
const menuHH = 8, | |
sidebarHH = 92; | |
// Scroll TODO | |
$(document).ready(function() { | |
let cachePosition = 0; | |
function st() { | |
return ($(window).scrollTop()-cachePosition >= 200 && cachePosition > 0)? "q": // To Back pos | |
($(window).scrollTop()-cachePosition >= 200)? "t": // ToTop | |
(cachePosition != 0)? "d": false; // To down or hide | |
} | |
// $(window).scroll(onScroll); | |
$(window).bind('mousewheel DOMMouseScroll', onScroll); | |
onScroll() | |
function onScroll() { | |
if(st() == "d") cachePosition = 0; | |
if (st()) $(".xScrollTD").fadeIn("slow"); | |
else $(".xScrollTD").fadeOut("slow"); | |
} | |
$(".xScrollTD").click(function() { | |
let gs = st(); | |
let scrollTop = parseInt($("#xFooter").offset().top); | |
scrollTop = (gs == "t")? 0: cachePosition; | |
cachePosition = (gs && gs != "q")? $(window).scrollTop(): 0; | |
$("html,body").animate({ scrollTop }, "slow"); | |
}); | |
}); | |
$(document).ready(function() { | |
// Menu | |
let stateMN = 0; | |
let autoHeightWrapper = 0, | |
autoHeightSticky = 0; | |
let cacheH = 0; | |
var stickyToggle = function (sticky, stickyWrapper, scrollElement) { | |
var stickyHeight = sticky.outerHeight(); | |
var stickyTop = stickyWrapper.offset().top; | |
if (scrollElement.scrollTop() >= stickyTop) { | |
if(stateMN != 1 || cacheH!=stickyHeight) { | |
cacheH = stickyHeight; | |
stateMN = 1; | |
} | |
else return; | |
stickyWrapper.css('height', autoHeightSticky); | |
// stickyWrapper.stop().animate({ height: stickyHeight }, 100, null, ()=> { stateMN = 1; }); | |
sticky.addClass("is-sticky"); | |
sticky.stop().animate({ backgroundColor: "#03479d", height: menuHH+"vh" }, 80); | |
} | |
else if(scrollElement.scrollTop() <= stickyTop+autoHeightSticky) { | |
if(stateMN != 2) { | |
stateMN = 2; | |
} | |
else return; | |
sticky.removeClass("is-sticky"); | |
stickyWrapper.css('height', 'auto'); | |
// stickyWrapper.stop().animate({ height: 0 }, 200); | |
sticky.css({ height: autoHeightSticky }); | |
sticky.stop().animate({ backgroundColor: "rgba(0, 0, 0, 0)", /*height: autoHeightSticky*/ }, 200); | |
} | |
}; | |
$('[data-toggle="sticky-onscroll"]').each(function () { | |
var sticky = $(this); | |
var stickyWrapper = $('<div>').addClass('sticky-wrapper'); | |
sticky.before(stickyWrapper); | |
sticky.addClass('sticky'); | |
// autoHeightWrapper = stickyWrapper.css('height', 'auto').height(); | |
autoHeightSticky = sticky.css('height', 'auto').height(); | |
$(window).on('scroll.sticky-onscroll resize.sticky-onscroll', function () { | |
stickyToggle(sticky, stickyWrapper, $(this)); | |
}); | |
stickyToggle(sticky, stickyWrapper, $(window)); | |
}); | |
// Sidebar | |
let sBar = $('.sidebar-slide'), | |
nowPHeight = $(sBar).parent().height(), | |
/*autoHeight = sBar.css('height', '100vh'),*/ | |
sbOffset = menuHH*$(window).height()/100; | |
let wWidth = $(window).width(); | |
$(window).resize(()=> { | |
wWidth = $(window).width(); | |
sbOffset = menuHH*$(window).height()/100; | |
}); | |
let stateSB = 0, hideProc = false; | |
if (sBar && !!sBar.offset()) { | |
let stickyTop = sBar.offset().top /*+ 17*/; | |
let otherContent = $(sBar).parent().children().not('.sidebar-slide'); | |
sBar.css({ height: ((wWidth < 1440)? "auto": sidebarHH+"vh") }); | |
$(window).scroll(function() { | |
if(wWidth < 1440) return sBar.css({ height: "100vh" }); | |
let windowTop = $(window).scrollTop(); | |
if (stickyTop < windowTop + sbOffset) { | |
show(); | |
} | |
else { | |
nowPHeight = $(sBar).parent().height(); | |
hide(); | |
} | |
if(hideProc) { | |
sBar.css({ top: hideProc - $(window).scrollTop() }); | |
} | |
}); | |
function show() { | |
if(stateSB != 1) { | |
stateSB = 1; | |
} | |
else return; | |
sBar.css({ position: 'fixed', top: menuHH+"vh" }); | |
otherContent.addClass("offset-lg-2"); | |
sBar.stop().animate({ height: sidebarHH+"vh" }, 300, null, ()=> { stateSB = 1; }); | |
} | |
function hide() { | |
if(stateSB != 2) { | |
stateSB = 2; | |
hideProc = sBar.offset().top; | |
} | |
else return; | |
sBar.stop().animate({ height: nowPHeight/*autoHeight*/ }, 300, ()=> { | |
sBar.css({ position: 'relative', top: 'initial' }); | |
otherContent.removeClass("offset-lg-2"); | |
hideProc = false; | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment