Welcome Guest, Not a member yet? Register   Sign In
Lightbox Close on ESC
#1

[eluser]Total Shop UK[/eluser]
I'm looking to close my lightbox by pressing the ESC key.
I've been able to get the code to react to the keypress but I can't seem to close lightbox.

Thanks

Complete code attached

ESC Keypress

Code:
function iclose(e) {
    var kcode = e ? e.which : window.event.keyCode;
    if (kcode==27 || kcode==0){
        $('lb').deactivate();
    }
}
document.onkeypress = iclose;
#2

[eluser]danmontgomery[/eluser]
Why not use lightbox2 or one of a dozen other similar plugins which close on escape by default?
#3

[eluser]Total Shop UK[/eluser]
Mainly because the lightbox I use is lightweight and fast.
I've got the lightbox to close on esc but it's messy Sad

Code:
function iclose(e) {
    lbox = document.getElementsByClassName("lbOn");
    var kcode = e ? e.which : window.event.keyCode;
    if (kcode==27 || kcode==0){
        var lb = new lightbox(lbox[0]);
        lb.deactivate();
    }
}
document.onkeypress = iclose;

If I press ESC then click the lightbox again it sends an extra lightbox for every click.
#4

[eluser]Total Shop UK[/eluser]
All sorted Smile

Code:
lightbox.prototype = {
    yPos: 0, xPos: 0, initialize: function (ctrl) {
        if (ctrl!='close'){
...
function initialize(close) {
if (close==1){
...




Theme © iAndrew 2016 - Forum software by © MyBB