Results 1 to 5 of 5

Thread: Use keybutton press instead of buttons for nav

  1. #1
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default Use keybutton press instead of buttons for nav

    here's the section i think that's using buttons for next and previous. it's allowing the viewer to move in a 3d room at 90 degree angles, one click at a time. i'd prefer to just use the arrow keys on the keyboard instead. anyway to do that?

    if( this.totalItems > 1 ) {
    this.$navPrev = $( '<span class="gr-prev">prev</span>' ).on( 'click', $.proxy( this.navigate, this, 'prev' ) );
    this.$navNext = $( '<span class="gr-next">next</span>' ).on( 'click', $.proxy( this.navigate, this, 'next' ) );
    this.$nav = $( '<nav/>' ).append( this.$navPrev, this.$navNext ).appendTo( $gallery );
    }

    it's from here
    http://tympanus.net/Development/3DGa...wallgallery.js
    http://tympanus.net/Development/3DGalleryRoom/

  2. #2
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Try adding an event listener for "keydown" then check the key codes.
    Left is 37 and right is 39.

    Based on the code you provided something like this could work.

    PHP Code:
    if( this.totalItems ) {
        
    this.$navPrev = $( '<span class="gr-prev">prev</span>' ).on'click', $.proxythis.navigatethis'prev' ) );
        
    this.$navNext = $( '<span class="gr-next">next</span>' ).on'click',  $.proxythis.navigatethis'prev' ) );
        
    this.$nav = $( '<nav/>' ).appendthis.$navPrevthis.$navNext ).appendTo$gallery );
        
        
    document.onkeydown = function(e) {
            
    || window.event;
            if(
    e.keyCode == "37") {
                $.
    proxy(this.navigatethis"prev");
            } else if(
    e.keyCode == "39") {
                $.
    proxy(this.navigatethis"next");
            }
        };
        


  3. The Following User Says Thank You to keyboard For This Useful Post:

    jundo12 (02-19-2016)

  4. #3
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    hmmm, it's not working. maybe i am doing something wrong. i've erased the original nav javascript snippet and inserted your version instead. did you look at the full javascript?
    http://tympanus.net/Development/3DGa...wallgallery.js the problem is, it isn't always moving in a straight line. every so often it turns a 90 degree corner. in my version of it, it turns that corner once per click, as i have each "wall" limited to displaying one image per wall. so each time the keypress would occur the window would have to display the 90 degree turn. the original nav does that so i'm pretty sure yours could as well, i just don't know why it isn't working.

    instead of allowing me to navigate the gallery with the keyboard, it makes the existing buttons turn the room in only one direction instead of either direction (left or right). so not only is it not allowing me to use the keyboard to navigate the gallery, it's breaking the original nav by always turning in one direction regardless of which button is pushed

    p.s a working version of the gallery is linked in my first post. its actually demo 2 that i'm using but it shares javascript with demo 1, so that's pretty much irrelevant. notice the foot prints are the buttons by which the gallery is navigated. in my version, the footprints are only left and right arrow graphics instead. i'd prefer not to use the arrow graphics and instead use the left and right arrow keys on keyboard to navigate
    Last edited by jundo12; 02-19-2016 at 06:02 PM.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't see where you tried the code suggested. Maybe you didn't successfully update the file? In any case, you don't need that even if it does work. Instead, you could simply add to the page itself here (at the end of the page, addition highlighted):

    Code:
    		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    		<script src="js/wallgallery.js"></script>
    		<script>
    			$(function() {
    
    				Gallery.init( {
    					layout : [3,2,3,2]
    				} );
    
    				$(document).keydown(function(e){
    					var k = e.keyCode - 38;
    					if(k * k === 1){
    						if(k > 0){ //next
    							Gallery.room.$navNext.trigger('click');
    						} else { // prev
    							Gallery.room.$navPrev.trigger('click');
    						}
    					}	
    				});
    
    			});
    
    		</script>
    Note: The added code is inserted before the closing brace and paran of the existing $(function() { call, but probably can go anywhere valid that also has access to jQuery and the document.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    thanks john! it works! woohoo. and very nicely i might add! the script couldn't be changed over the net because it's not my script. its mit licensed and located at
    tympanus.net.

Similar Threads

  1. Different image when you press F5
    By cocoalex in forum JavaScript
    Replies: 12
    Last Post: 08-31-2008, 01:00 AM
  2. keyUp on 4th Press
    By tomyknoker in forum JavaScript
    Replies: 8
    Last Post: 08-31-2007, 09:16 AM
  3. Email/Press Form
    By add in forum HTML
    Replies: 5
    Last Post: 04-19-2006, 06:25 AM
  4. Auto Redirect on key press?
    By BLiZZaRD in forum PHP
    Replies: 10
    Last Post: 03-29-2006, 03:26 PM
  5. Shift key press
    By NCA in forum JavaScript
    Replies: 1
    Last Post: 02-01-2006, 06:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •