Tagged: x
-
AuthorPosts
-
September 5, 2016 at 1:54 pm #1162004
ellenrocoParticipantHello, wondering if anyone can help.
URL: http://www.pureactive.co.uk
Wordpress Version: 4.6
X Version: Child theme (unsure from which version)
Cornerstone Version: 1.3.0After opening the mobile menu and tapping a section, it jumps to it (the website is one page) but the menu doesn’t automatically close. If you tap the burger again to close, it jumps back to the top.
Also the smooth scroll doesn’t work properly in mobile or desktop versions. I did add some custom jQuery to make the menu stick by changing classes, would this cause problems?
Many thanks,
EllenSeptember 5, 2016 at 2:00 pm #1162013
JadeModeratorHi Ellen,
You can add this under Custom > JS in the Customizer.
jQuery(function($){ $('.mobile .x-nav a').on('touchend click', function(){ $('.x-btn-navbar').click(); }); });Hope this helps.
September 6, 2016 at 4:00 pm #1163523
ellenrocoParticipantThanks very much, that helped with the closing issue.
Do you know why the smooth scrolling doesn’t work? Also, if you tap the menu button again, it still jumps to the top of the page.
Thanks again.
September 7, 2016 at 12:13 am #1163986
ChristopherModeratorHi there,
Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / passwordDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thanks.
September 7, 2016 at 3:02 pm #1165046
ellenrocoParticipantThis reply has been marked as private.September 7, 2016 at 6:50 pm #1165332
JadeModeratorHi Ellen,
Please try to add this code in the JS customizer:
jQuery(document).ready(function($) { var $body = $('body'); var bodyHeight = $body.outerHeight(); var adminbarHeight = $('#wpadminbar').outerHeight(); var navbarFixedTopHeight = $('.x-navbar-fixed-top-active .x-navbar').outerHeight(); var locHref = location.href; var locHashIndex = locHref.indexOf('#'); var locHash = locHref.substr(locHashIndex); // // Calculate the offset height for various elements and remove it from // the element's top offset so that fixed elements don't cover it up. // function animateOffset( element, ms, easing ) { $('html, body').animate({ scrollTop: $(element).offset().top - adminbarHeight - navbarFixedTopHeight + 1 }, ms, easing); } // // Page load offset (if necessary). // $(window).load(function() { if ( locHashIndex !== -1 && $(locHash).length ) { animateOffset(locHash, 1, 'linear'); } }); // // Scroll trigger. // $('a[href*="#"]').on('touchstart click', function(e) { $href = $(this).attr('href'); notComments = $href.indexOf('#comments') === -1; notAccordion = $href.indexOf('#collapse-') === -1; notTabbedContent = $href.indexOf('#tab-') === -1; if ( $href !== '#' && notComments && notAccordion && notTabbedContent ) { var theId = $href.split('#').pop(); var $el = $('#' + theId); if ( $el.length > 0 ) { e.preventDefault(); animateOffset($el, 850, 'easeInOutExpo'); } } }); // // Initialize scrollspy. // if ( $body.hasClass('x-one-page-navigation-active') ) { $body.scrollspy({ target : '.x-nav-wrap.desktop', offset : adminbarHeight + navbarFixedTopHeight }); // // Refresh scrollspy as needed. // $(window).resize(function() { $body.scrollspy('refresh'); }); var timesRun = 0; var interval = setInterval(function() { timesRun += 1; var newBodyHeight = $body.outerHeight(); if ( newBodyHeight !== bodyHeight ) { $body.scrollspy('refresh'); } if ( timesRun === 10 ) { clearInterval(interval); } }, 500); } });Hope this helps.
September 8, 2016 at 5:17 pm #1167108
ellenrocoParticipantThank you! This is so much better, the smooth scrolling works perfectly. The only final problem is the page jumping back to the top the second time you tap the mobile menu button. Any ideas on what’s causing that? Thanks again!
September 9, 2016 at 1:02 am #1167574
Paul RModeratorHi,
Please change the code provided above to this.
jQuery(document).ready(function($) { $('a[href*="#"]').off('touchstart click'); var $body = $('body'); var bodyHeight = $body.outerHeight(); var adminbarHeight = $('#wpadminbar').outerHeight(); var navbarFixedTopHeight = $('.x-navbar-fixed-top-active .x-navbar').outerHeight(); var locHref = location.href; var locHashIndex = locHref.indexOf('#'); var locHash = locHref.substr(locHashIndex); // // Calculate the offset height for various elements and remove it from // the element's top offset so that fixed elements don't cover it up. // function animateOffset( element, ms, easing ) { $('html, body').animate({ scrollTop: $(element).offset().top - adminbarHeight - navbarFixedTopHeight + 1 }, ms, easing); } // // Page load offset (if necessary). // $(window).load(function() { if ( locHashIndex !== -1 && $(locHash).length ) { animateOffset(locHash, 1, 'linear'); } }); // // Scroll trigger. // $('a[href*="#"]').not('.x-btn-navbar').on('touchstart click', function(e) { $href = $(this).attr('href'); notComments = $href.indexOf('#comments') === -1; notAccordion = $href.indexOf('#collapse-') === -1; notTabbedContent = $href.indexOf('#tab-') === -1; if ( $href !== '#' && notComments && notAccordion && notTabbedContent ) { var theId = $href.split('#').pop(); var $el = $('#' + theId); if ( $el.length > 0 ) { e.preventDefault(); animateOffset($el, 850, 'easeInOutExpo'); } } }); // // Initialize scrollspy. // if ( $body.hasClass('x-one-page-navigation-active') ) { $body.scrollspy({ target : '.x-nav-wrap.desktop', offset : adminbarHeight + navbarFixedTopHeight }); // // Refresh scrollspy as needed. // $(window).resize(function() { $body.scrollspy('refresh'); }); var timesRun = 0; var interval = setInterval(function() { timesRun += 1; var newBodyHeight = $body.outerHeight(); if ( newBodyHeight !== bodyHeight ) { $body.scrollspy('refresh'); } if ( timesRun === 10 ) { clearInterval(interval); } }, 500); } });Hope that helps.
September 10, 2016 at 1:47 pm #1169431
ellenrocoParticipantDid you move my custom JS around? I think I replaced the wrong part and now it doesn’t work at all… Definitely should have backed this up first… Do you have a backup? My menu doesn’t stick to the top now any more. Thanks.
September 11, 2016 at 1:09 am #1169821
RadModeratorHi there,
We don’t have any backup as we didn’t edit your existing code. I can confirm that some codes are misplaced and deleted. But I’m not really sure how it was setup and I’m afraid to touch it. Would you mind requesting a restoration from your hosting?
Thanks!
September 11, 2016 at 6:49 am #1170045
ellenrocoParticipantThanks Rad, definitely my own fault for not copying it first. I do have some backups through the updraft plugin, do you know where I would find a file with this custom JS that I can copy back in? Or as it’s part of the page might it be in the database backup? I’d rather not have to restore totally, but no worries if not.
Thanks again!
September 11, 2016 at 7:33 am #1170068
ChristianModeratorHey Ellen,
Your will have to restore the database.
Thanks.
September 11, 2016 at 8:23 am #1170107
ellenrocoParticipantRight I’ve go it back to how it was after adding the second code from Jade which fixes the smooth scrolling, but then tried replacing that with the code from Paul R, which doesn’t seem to work on the jumping to the top issue, and breaks the first fix for the menu staying open, so I removed it again.
Any suggestions here on how to stop the page jumping to the top after tapping the mobile menu button a second time? Otherwise I’ll settle for leaving it as is.
Thanks for all your help so far!
September 11, 2016 at 4:55 pm #1170427
RadModeratorHi there,
You mean the mobile hamburger icon right?
Please add this
jQuery( '.x-btn-navbar' ).off('touchstart touchend').on('click', function(e){ e.preventDefault(); });Hope this helps.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1162004 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
