Closing gallery with arrow keys

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Closing gallery with arrow keys

Ivan
I want Shadowbox to close after the last image in the gallery when the user is advancing with the arrow key.
I do it by making the gallery continous (continuous:true,) and adding:
onChange: function() {
                if(Shadowbox.current ==0){Shadowbox.close();}
    }
Is there a better way? This is abrupt and also requires some additional code to detect if the user is going backwards, so not a great solution but it is handy because it works for all galleries regardless of number of images. - Ivan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Closing gallery with arrow keys

Ivan
also throws a js error (line 8 of shadowbox.js):
"Uncaught TypeError: Cannot read property 'remove' of null "
so I think I can't use this method.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Closing gallery with arrow keys

Ivan
ended up taking some time to do this properly (at least I think this is correct...):

document.onkeydown = mykeydown;

function mykeydown(x) {
   x = x || window.event;

    if (x.keyCode == '39') {
                mylength = Shadowbox.gallery.length;
                mycurrent = Shadowbox.current;
                if (mylength - mycurrent == 1) {Shadowbox.close();}
    }
}
Loading...