The Fancybox popup consistently stays at the forefront while scrolling

After integrating the fancybox plugin into my website, I encountered an issue that needs attention:

Whenever I click on an image, it opens correctly but unexpectedly scrolls to the top of the page, preventing me from scrolling down while the popup is displayed. The problem can be observed on my website here.

I attempted to resolve this by utilizing the "scrollOutside" option, but unfortunately, it did not rectify the situation.

Your assistance with this matter would be greatly appreciated. Thank you!

Answer №1

Just a heads up before I share my solution, the scrolling issue is not related to fancybox itself. You can easily verify this by testing it in the browser console on other pages:

$.fancybox("test");

On this particular page, there are multiple scrollable <div> sections. You might need to scroll back to the correct section. Below is the solution for scrolling back.

Firstly, we save the current page when you click on it.

var currentPage = "homepage";
$(".page").click(function(){
    currentPage = $(this).attr("id");
});

Now, you can easily scroll back to that page whenever needed. For example, using the onClosed event:

$("a.inline").fancybox({
    // ... other settings ...
    'onClosed' : function() {
        $("html,body").scrollTop($("#"+currentPage).offset().top);
    }
});

If this doesn't seem to work, feel free to inform me.

Answer №2

Your CSS has a specific selector causing the issue that needs to be addressed.

html , body {
    height: 100%;
}

If you remove html from this rule, it should solve the problem. When setting 100% height for the <html> tag, the overflow behavior may not function as expected.

Alternatively, you can apply inline styles directly to the <html> tag by setting height: auto;. Try this out in your console and test scrolling when viewing an image to see the difference in behavior.

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

Semi-transparent image

Can I achieve a semi-transparent image? Similar to this gradient: background:linear-gradient(to bottom,rgb(44, 44, 44),rgb(29, 38, 51,0.322)); ...

Display elements exclusively when the class XY is in an active state using JavaScript

Hello everyone, I'm new to this platform and excited to share my first post. Currently, I find myself facing a major challenge as I navigate through a bootcamp program. I have been working on a website with different sections that require specific fu ...

Iterating over images and displaying them in Laravel's blade templating engine, updating outdated Angular code

Currently, I am in the process of transitioning an Angular repeat function used for displaying images on our website (built with Laravel). The goal is to eliminate Angular completely and handle everything using Laravel loops in the blade template. I have ...

Transforming HTML with JavaScript

I am facing a challenge in my JavaScript application where I receive HTML code from an endpoint that contains radio buttons. Unfortunately, I cannot modify the HTML content coming from this endpoint. My goal is to convert these radio buttons into regular b ...

The query attribute of the http_incomingmessage in Node.js is not empty, causing Express to have trouble parsing the query parameter

While utilizing node version 6.9.4 and express version 4, there seems to be an issue with the creation of the IncomingMessage object in _http_common.js. Specifically, on line number 60, the parser.incoming.query function is being set to a value (usually it ...

Why is Django not recognizing my ajax request when using the `is_ajax()` function?

After sending a GET request and processing the data to obtain a redirect link, the function seems to be having trouble entering the is_ajax() block. $(document).on('click', '.top_up_pay', function (e) { var post_data; e.preventDefa ...

Guide to building a dual recursion menu in AngularJS using both functional and template methods

I'm currently working on developing a menu in AngularJS using template and functional recursion. The code I have written involves quite a bit of recursion, so I could really use some assistance. Below is the menu data represented in JSON format: var ...

Is it possible to incorporate a label within a dropdown menu (<select>)?

How can I add a label inside a select box using Bootstrap? Here is an example: Before selecting an option After selecting an option, the label should appear in a small size like this: After selecting an option : <div class="form-group"> & ...

The script fails to start using npm start, however, it runs smoothly when using node server.js

For a while now, I've been facing an issue that I just can't seem to resolve. When I navigate to my project's src folder and execute `node server.js`, everything functions as expected. I can access the application at http://localhost:3000/cl ...

Unforeseen Extra Information is being transmitted along with Socket.io and Jquery

Issue : There seems to be a problem with the chat message printing an extra character in msg. Upon console logging, an additional object value is appearing in the state. What could be causing this issue? Console log output : 2{"message":"e"} 1{"mess ...

How to increase the ng-repeat index value in HTML

Is it possible to increase the value of $index within an ng-repeat loop? Let's consider this example: <div ng-repeat:x in ProductList"> <label>{{x}}</label> // if x = 1 x++; // I need help with this line <label st ...

What are some strategies for improving search efficiency in arrays containing over 50,000 elements?

I am working with a large array of strings containing about 50,000 elements. export const companies = [ "000014", "000016", "000017", "000019", "000020", "000021", "000023" ...

Headers cannot be reset after being sent while attempting to log in a user

I'm very puzzled at the moment, as I'm utilizing bcrypt to authenticate a user login and encountering an unexpected error: Error: Can't set headers after they are sent. Let me share with you the code snippet for that particular route: rou ...

Error encountered in Express Router middleware (`app.use() function must be provided with a middleware function`)

I've seen plenty of similar questions on this topic, but after reviewing them all, I still haven't found a solution. My current dilemma involves creating an app using Express Router, however I keep encountering the following error: app.use() re ...

What is the solution to preventing Angular 1.3 ngMessages from affecting the size of my form?

Hey there, I'm diving into front-end design for the first time. My issue is with a form that I want to use ng-messages for validation error messages. Currently, my form's size changes depending on whether there are errors displayed or not, and it ...

Tracking changes in local storage through mapped React components

I'm currently working on implementing a cart feature, where I've already set up the cart in local storage using JSON. However, I'm facing an issue when trying to allow users to adjust the quantity of each product in the cart. The handleItem ...

Foundation 6 Websites - Dropdown Automatically Close When Clicked

I am currently using foundation 6.2 to create the registration page for my website. So far, everything is functioning as expected. However, I am now looking to have a dropdown pane open when an input field is focused on and close when the focus is removed. ...

Tips for adjusting CSS font sizes within a contenteditable element?

I am looking to develop a compact HTML editor using JavaScript that allows me to customize the font-size of selected text with a specific CSS value. The documentation states that the FontSize command is used like this: document.execCommand("FontSize", fal ...

I encountered an issue while attempting to link my project to a database. An error popped up stating that the name 'textbox' does not exist in the current context

I encountered an error when trying to connect my project to a live database. The error message stated: the name ‘textbox’ does not exist in the current context. How can I resolve this issue? Below is the aspx.cs code that I used for the connection, wh ...

What steps are needed to adjust a modal window so that it perfectly fits the size of the image it contains?

I am currently utilizing Bootstrap 4.2 to create a popup window (modal) featuring an image displayed at its real size (100%) in both width and height, provided that the browser window size permits. If the image surpasses the window dimensions, it should au ...