switching between div and fixed positioning for lightbox functionality

I am working on an HTML file

<html>
<body>
<div #main> <a click to open lightbox> <img> <more images> </a> </div>
</body>
</html>

After the lightbox opens, the code looks like this:

 <html>
    <body>
    <div id="main"> <a click to open lightbox> <img> <more images> </a> </div>
    <div id="pic_holder">...Popup div content </div>
    <div id="overlay"></div>
    </body>
    </html>

I am trying to make #main no scroll. I have tried using CSS properties like overflow:hidden and position:static. My CSS code includes .noscroll{}.

The issue is that even if I apply overflow:hidden to #main to prevent scrolling, the body still scrolls. And when I use position:static on #main, the body scrolls back to the top after the popup is closed. I want to achieve a Pinterest-like behavior and I am using prettyphoto.

If you have any tips or suggestions, please let me know. This problem is somewhat related to Preventing div scrolling back to top when changing position to fixed, but it doesn't address the specific issue of adding a lightbox.

Answer №1

Looking for some code improvements, here are a few pointers:

  1. Try setting your body to "overflow:hidden".

  2. The scrolling behavior depends on the element you're hovering over; have you considered setting the size of #main equal to the window size?

Best regards

[update]

After reviewing your website, here are some changes I recommend:

  1. Make "pp_pic_holder" a child of "pp_overlay".
  2. Style "pp_pic_holder" in CSS rather than using fixed positioning; try using "margin: 0 auto;".
  3. In jQuery, use the "resize" function on windows to set the width/height of "pp_overlay" to match the window dimensions. Here's an example:

    function overlayResize(){
       var WW=$(window).width();
       var WH=$(window).height();
       $(".overlay").height(WH).width(WW);
    }
    
    $(window).resize(function(){
        overlayResize();
    })
    
    overlayResize();
    

Here's a jsFiddle demonstration of what I've described:

http://jsfiddle.net/kirkas/PSjTD/

[update] If you want scrolling within the overlay, remember to add:

    overflow:auto;

to your overlay.

http://jsfiddle.net/kirkas/PSjTD/

[Update]

This modification prevents the hiding function from triggering when clicking on selected images.

http://jsfiddle.net/kirkas/PSjTD/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the most effective way to incorporate the Gmail compose window concept into Single Page Applications?

I am currently working on a project that would benefit from a user-friendly way to add transactions quickly. I am intrigued by the idea of creating something similar to the Gmail compose pop-up feature on a single page. I am unsure of how to go abo ...

The scaling feature in CSS does not function properly in Internet Explorer 8

I've tried multiple approaches to transform the IE Matrix, but I'm facing an issue with the transform scale CSS not functioning in IE8. Code: .fture_box ul li.fture_img img{ width: 451px; height: 284px; display: block; margin: 0 0px 0 11px; pad ...

Ways to add style to Chrome without causing any changes in Edge

I'm working on fixing a bug in Chrome and have successfully applied a style to correct it. However, when I view it in Edge, the appearance is not right. How can I target only Chrome (version 60) with my styles, without affecting other browsers? @medi ...

Are there any other CSS methods available to address the limited support for flex-grow in Safari?

I'm currently developing an interactive "accordion" component that can accommodate multiple child elements. Each child item closes to the height of its header, but expands evenly with other open siblings when activated. If this explanation is unclear, ...

Encountering an undefined json array when making an AJAX request

There have been numerous questions on this topic, but none of the specific solutions seemed to apply to my situation. So, I apologize if this is a duplicate query. I am currently working on fetching data from an SQL database using a PHP file that passes t ...

Leveraging jQuery to implement onclick functionality within a Jinja2 loop

I'm currently working with Python, Flask, and Jinja2. When using a for loop, I want to be able to click on the {{ place.place_photo }} element to toggle its details. Initially, I had it functioning correctly but ran into an issue where clicking on on ...

Activate animation while scrolling the page

I am using a progress bar with Bootstrap and HTML. Below is the code snippet: $(".progress-bar").each(function () { var progressBar = $(this); progressBar.animate({ width: progressBar.data('width') + '%' }, 1500); }); <body> & ...

How can I position a div element inside another fixed div element?

I'm working on a layout with a fixed gradient div that contains all my content. However, I want the content to be scrollable instead of fixed. How can I make this happen? Here is the current structure: <body> <div class="wrappe ...

Responsive CSS design that adjusts to fit the content

Struggling to make the wrapper expand with its content... This is the structure: * { padding: 0; margin: 0; } body { background-color: #ccc; background-repeat:repeat; font: Tahoma, Geneva, sans-serif; color: #FFF; } .wrapper { width: 95%; margin: 0 au ...

What are some methods for toggling text visibility in PHP?

I am facing confusion regarding the functionality of this code. Here is the snippet in question : //start date to end date <?php if($show5 < $show6) { ?> <a>show content</a> <?php }?> If both 'start da ...

The JavaScript operator that functions in a manner akin to the SQL "like"

I am working on a jQuery function that needs to perform like the "like" operator. Can anyone help me achieve this? Your assistance is greatly appreciated. The function currently only works if I search for the whole word, for example: var vsearch = "home" ...

Angular and Datepair seem to have trouble cooperating

I've been struggling to solve this issue for a few days now and I feel like it's time to seek help from you wonderful people. I am currently developing a calendar application using Angular along with the datepair/datepicker/timepicker libraries. ...

What is the best way to style my navigation bar using HTML and CSS?

Exploring the world of web design as a recent enthusiast, I delved into the basics some time ago only to forget them shortly after. My interest reignited a few months back, leading me to create my own web pages for practice and skill enhancement. However, ...

Creating a jQuery selector that is not case-sensitive

I have a query where I want to ensure it is case-insensitive: var matches = $(this).find('div > span > div#id_to_find[attributeName ^= "filter"]'); if (matches.length > 0) { } Is there a way to make the selector ^= case-insensitive? Pe ...

Using jQuery to send a POST request via Ajax

Hi there, I am currently integrating with the Box API and they have provided a curl command to obtain the access token. Here is the command: curl https://www.box.com/api/oauth2/token \ -d 'grant_type=authorization_code&code={your_code}&c ...

Header of table remains fixed as user scrolls through data, allowing for easy reference. The left

Above, I have utilized some code from another answer here to display a table. However, I am now contemplating the possibility of customizing it so that the first column remains fixed for horizontal scrolling. Currently, I'm employing the following as ...

CakePHP is experiencing issues displaying images from the Blueimp file uploader

After incorporating CakePHP, I am experiencing an issue where the list of files shows no errors in the debug. {"files": [ {"name":"download.jpg","size":19415,"url":"http:\/\/amportal.local\/app\/webroot\/files&bs ...

Reveal/Conceal footer upon vertical scrolling

I am attempting to achieve the following goals: Display the div element when the scrolling position is greater than 20 Apply a fadeOut effect after a certain delay Prevent the fadeOut effect when hovering over the sticky footer This is my implementation ...

Achieving full child div coverage within a bordered parent div on Chrome

I am encountering an issue where I am trying to insert an image into a bordered div, but in Chrome 96.0 there are unexpected margins appearing from the top and left that I cannot seem to remove. Below is the code I am using: .wrapper { width: 36px; ...

Height CSS does not conceal side bar hyperlinks

CSS .nested-menu { .list-group-item { cursor: pointer; } .nested { list-style-type: none; } ul.submenu { height: 0; } & .expand { ul.submenu { ...