let initSubHeaderOffsetTop = 500; let parallaxActive = true; $(document).ready(function () { initSubHeaderOffsetTop = $('#profile-sub-header').offset().top; $('section[data-type="background"]').each(function () { var $bgobj = $(this); $bgobj.css('height', parseFloat($('#profile-sub-header').css('top')) - $(window).scrollTop() - 60); $(window).scroll(function () { if (parallaxActive) { let translateY = $('#profile-sub-header').css('transform'); if (translateY !== 'none') { translateY = matrixToArray(translateY); translateY = parseFloat(translateY[translateY.length - 1]); } else { translateY = 0; } $bgobj.css('height', 500 + translateY - $(window).scrollTop() - 60); } }); }); $('section[data-type="foreground"]').each(function () { const $bgobj = $(this); $(window).scroll(function () { if (parallaxActive) { const yPos = -($(window).scrollTop() / $bgobj.data('speed')); const coords = '50% ' + yPos + 'px'; $bgobj.css({backgroundPosition: coords}); $bgobj.css('transform', 'translate3d(0,' + yPos + 'px, 0)') } }); }); }); function matrixToArray(str) { return str.split('(')[1].split(')')[0].split(','); } $(window).scroll(function () { const scrollTrigger = $('#scroll-trigger'); if ($(this).scrollTop() + 75 > scrollTrigger.offset().top) { parallaxActive = false; $('#profile-sub-header').addClass('fixedTop').css('transform', 'translate3d(0,0,0)'); $('#profile-content').css('transform', 'translate3d(0, ' + $('#profile-sub-header').height() + 'px, 0)'); } else { parallaxActive = true; $('#profile-sub-header').removeClass('fixedTop'); } }); const subButton = $('.subscribe-button'); const subbedClass = 'subbed'; subButton.on('click', function (e) { sendFollowerRequest(); e.preventDefault(); }); function toggleSubbed(isSubbed) { let count = subButton.attr('data-count'); if (isSubbed) { subButton.removeClass(subbedClass); count--; } else { subButton.addClass(subbedClass); count++; } subButton.attr('data-count', count); } function sendFollowerRequest() { $.ajax({ url: "/user/switchFollowing", method: "POST", success: function (data) { switch (data.code) { case 0: $('#mustBeLoggedInModal').modal('show'); break; case 1: $('#cantFollowYourself').modal('show'); break; case 10: toggleSubbed(true); break; case 11: toggleSubbed(false); break; default: break; } }, }); } $(document).ready(function () { $(".vertical-tab-menu>.list-group>a").click(function (e) { e.preventDefault(); $(this).siblings('a.active').removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".vertical-tabs>.vertical-tab-content").removeClass("active"); $(".vertical-tabs>.vertical-tab-content").eq(index).addClass("active"); }); });