Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 922909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:06:28+00:00 2026-05-15T19:06:28+00:00

I got two divs, one is a background and the other is the container

  • 0

I got two divs, one is a background and the other is the container for a vid which is on top of the former. Another div serves as a button that when clicked, it triggers the lightbox. Here’s my code:

//0 means disabled; 1 means enabled;

var popupStatus = 0;
var buttonDivID = "";
var conDivID = "";

//determine which div is clicked

function whichDiv( div ) {
    if( div==1){
        buttonDivID = "#vid";
        conDivID = "#popupContact";
    }
}

//loading popup with jQuery magic!

function loadPopup(){

    //loads popup only if it is disabled

if(popupStatus==0){

    $("#backgroundPopup").css({

        "opacity": "0.7"

    });

    $("#backgroundPopup").fadeIn("slow");

    $(conDivID).fadeIn("slow");

    popupStatus = 1;
}
}

//disabling popup with jQuery magic!

function disablePopup(){

//disables popup only if it is enabled

if(popupStatus==1){

    $("#backgroundPopup").fadeOut("slow");

    $(conDivID).fadeOut("slow");

    popupStatus = 0;
    buttonDivID = "";
    conDivID = "";
}
}

//centering popup

function centerPopup(){

//request data for centering

var windowWidth = document.documentElement.clientWidth;

var windowHeight = document.documentElement.clientHeight;

var popupHeight = $(conDivID).height();

var popupWidth = $(conDivID).width();

//centering

$(conDivID).css({

    "position": "absolute",

    "top": windowHeight/2-popupHeight/2,

    "left": windowWidth/2-popupWidth/2
});

//only need force for IE6

$("#backgroundPopup").css({

    "height": windowHeight

});
}

//CONTROLLING EVENTS IN jQuery

$(document).ready(function(){

//LOADING POPUP

//Click the button event!

$(buttonDivID).click(function(){

    //centering with css

    centerPopup();

    //load popup

    loadPopup();
});


//CLOSING POPUP

//Click the x event!

$("#popupContactClose").click(function(){

    disablePopup();

});

//Press Escape event!

$(document).keypress(function(e){

    if(e.keyCode==27 && popupStatus==1){

        disablePopup();
    }
});
});

I should mention that I didn’t create this code, I just modified it to fit my needs. The problem here is that when I click anywhere on the page except the button div, the background div of the lightbox pops up. And when I close the vid container, the background div remains visible which is not what I want. Could you pls tell me what’s wrong with my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:06:29+00:00Added an answer on May 15, 2026 at 7:06 pm

    Maybe I’m missing something, but it looks like the buttonDivID is only being set in the whichDiv function, which is never being called. I would start there…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've got two developers on the same closed (ugh, stupid gov) network, Another developer
<div> <div class=one>One</div> <div class=two>Two</div> <div class=three>Three</div> <div class=four>Four</div> <div class=five>Five</div> </div> I need
I've got two models: Message and Attachment. Each attachment is attached to a specific
I've got two Silverlight Controls in my project, both have properties TeamId. I would
I've got two controls in my Interface Builder file, and each of those controls
I've got two SVN branches (eg development and stable) and want to switch from
I've got two tables in my database: Articles and Tags The Tags tables consist
I've got two tables: TableA ------ ID, Name TableB ------ ID, SomeColumn, TableA_ID (FK
I've got two arrays of the same size. I'd like to merge the two
Say I've got two scheduled processes: A and B. Given that B should not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.