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

  • Home
  • SEARCH
  • 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 7626583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:20:40+00:00 2026-05-31T05:20:40+00:00

I created a light box from scratch in JQuery, it works well, My problem

  • 0

I created a light box from scratch in JQuery, it works well, My problem is that when you click what you want to pop up, it pops up on an absolute position on the page, so if you’re scrolled all the way to the bottom and click on something, you have to scroll all the way up to see what popped up. Here’s my CSS… the element’s postion is the class of “outer”:

.outer{
    display:none; 
    width:770px; 
    height:475px; 
    top:25%; 
    left:17.5%; 
    position:absolute;
    z-index:3; 

}
.inner{
    width:750px; 
    height:450px; 
    background-color:white; 
    border:1px solid #000; 
    -moz-box-shadow:0px 0px 10px #111; 
    -webkit-box-shadow:0px 0px 10px #111; 
    box-shadow:0px 0px 10px #111; 
    margin-top:15px;
    z-index:4;
}


.exit_button{ 
    float:right;
    z-index:6;
    cursor: pointer;
}
.inner_content{
    display:none;
    z-index:99;
 }
.next{
    cursor: pointer; 
    margin-left:240px; 
}

.previous{
    cursor: pointer; 
    margin-left:275px;
}

Here’s my JQuery in case this needs to be done in JQuery:

$(document).ready(function() {
    $('.button1').click(function() {
        var get_id = $(this).attr('id');        
        var current = $('#div_pic_'+get_id);
        current.show();         
        if (current.is(':last-child')) {
            $('.next').prop('disabled', true);
            $('.previous').prop('disabled', false);
        }
        else if (current.is(':first-child')) {
            $('.previous').prop('disabled', true);
            $('.next').prop('disabled', false);

        }
        else
        {
            $('.next').prop('disabled', false);
            $('.previous').prop('disabled', false);
        }

        $('.outer').fadeIn(750);        
        $('.button1').unbind('click');

});

$('.exit_button').click(function() {
        $('.button1').bind('click', function() {

        var get_id = $(this).attr('id');        
        var current = $('#div_pic_'+get_id);
        current.show();         
        if (current.is(':last-child')) {
            $('.next').prop('disabled', true);
            $('.previous').prop('disabled', false);
        }
        else if (current.is(':first-child')) {
            $('.previous').prop('disabled', true);
            $('.next').prop('disabled', false);

        }
        else
        {
            $('.next').prop('disabled', false);
            $('.previous').prop('disabled', false);
        }

        $('.outer').fadeIn(750);        
        $('.button1').unbind('click');

});

        $('.outer').fadeOut();
        $('.inner_content').hide();

});


$('.next').click(function() {         
        var current1 = $('.inner_content:visible');
        var nextSlide = current1.next('.inner_content');
        if (current1.is(':last-child')) {
            $('.next').prop('disabled', true);
            $('.previous').prop('disabled', false);
        }
        else
        {
        current1.hide();
        nextSlide.show();
        $('.next').prop('disabled', false);
        $('.previous').prop('disabled', false);
        }
});


$('.previous').click(function() {
        var current2 = $('.inner_content:visible');
        var prevSlide = current2.prev('.inner_content');
        if (current2.is(':first-child')) {
            $('.previous').prop('disabled', true);
            $('.next').prop('disabled', false);
        }
        else
        {
        current2.hide();
        prevSlide.show();
        $('.next').prop('disabled', false);
        $('.previous').prop('disabled', false);
        }

});





});

This is like one of my first JQuery projects so my coding may suck.

and a quick version of my HTML:

<img src="whatever.png" id="001" class="button1" />

<div class="outer">
<img src="images/closebox.png" class="exit_button" />
<div class="inner">

<div class="inner_content" id="div_pic_001">
</div>

</div>   
<button class="previous">Prev</button><button class="next">Next</button>    
</div>

This all works great, just how would I get it to pop up in the center of the area the user is viewing? I tried to do it in CSS with percentages, but that only works if the page is a static height and doesn’t scroll past the top. Any CSS tricks to do this or do I have to add this into my JQuery and how would I go about that?
Thank you
-Mike

  • 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-31T05:20:41+00:00Added an answer on May 31, 2026 at 5:20 am

    You can use jQuery to center the image in the window.

    jQuery.fn.center = function () {
      this.css("position","absolute");
      this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
      this.css("left", (($(window).width() - this.outerWidth()) / 2) + enter code here$(window).scrollLeft() + "px");
      return this;
    }
    

    Code from this post

    Then:

    $('.outer').center().fadeIn(750);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my own light box, the problem is that it shows centered
I want to create a sort of light/thick box that only acts on a
So I have a light box that's dynamically loaded from a common.js file. (Legacy
I've created solution to reproduce a problem that I'm having with MVVM-Light EventToCommand vs
I created a FlatCombo Style that I want to apply to a combo box.
I created a django form and want to display it in a light box
A while back I created a lightbox plugin using jQuery that would load a
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a BeginInvoke so I could write to a text box from a
I want to create a multi select box (click and drag at empty space

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.