Tagged: x
-
AuthorPosts
-
May 6, 2016 at 8:21 am #978571
belayachimarouaneParticipantHello,
My website is made of full height sections and I want to be able to navigate from a section to another by hitting up and down keyboard shortcuts.
I used this JS code but it doesn’t seem to work :function scrollToAnchor(aid){ $('html,body').animate({scrollTop: aid.offset().top},'slow'); } var i = 1; $(document).keydown(function (event) { if (event.keyCode == 38) { i--; scrollToAnchor($("#Section"+i+"")); } else if (event.keyCode == 40) { i++; event.preventDefault(); scrollToAnchor($("#Section"+i+"")); } });Any idea on how to make it work ?
Thanks a lot
May 6, 2016 at 1:46 pm #978970
belayachimarouaneParticipantThe code finally worked by naming each section : Section1, Section2 ….
However when I press down or up with my keyboard it takes me a bit further than I want, and the menu isn’t calculated while scrolling with keyboard.Any suggestion on how to solve it ?
Thanks a lot
May 6, 2016 at 4:14 pm #979325
JadeModeratorHi there,
Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
May 8, 2016 at 4:04 am #980839
belayachimarouaneParticipantHello,
Here is the link http://garcondusiecle.com/
When you click on down or up with keyboard it works and takes you to the next section, however it goes so far and and the menu hides a part of the section.
Many thanks!
May 8, 2016 at 4:17 am #980847
Nabeel AModeratorHi again,
Please try replacing your code with this one:
function scrollToAnchor(aid){ var headerHeight = $('.x-navbar').height(); $('html,body').animate({scrollTop: aid.offset().top - headerHeight },'slow'); } var i = 1; $(document).keydown(function (event) { if (event.keyCode == 38) { i--; scrollToAnchor($("#Section"+i+"")); } else if (event.keyCode == 40) { i++; event.preventDefault(); scrollToAnchor($("#Section"+i+"")); } });Don’t forget to clear your browser’s cache after adding the code. Let us know how this goes!
May 8, 2016 at 5:54 am #980897
belayachimarouaneParticipantHello, I have replaced it but the keyboard navigation isn’t working at all now..
Thanks a lot!
May 8, 2016 at 3:21 pm #981289
RadModeratorHi there,
The naming is now #section instead of #Section. Please change this
scrollToAnchor($("#Section"+i+""));to this.
scrollToAnchor($("#section"+i+""));Thanks!
May 9, 2016 at 6:05 am #982043
belayachimarouaneParticipantAMazing!!! Thanks a lot
May 9, 2016 at 7:38 am #982140
Paul RModeratorYou’re welcome! 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-978571 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
