Firefoxy can't seem to get through the navigation keys within an element that has a hidden

Check out this fiddle I created: http://jsfiddle.net/c11khcak/13/. My goal is to hide the scrollbar of an element while still allowing it to be scrollable using the mouse wheel and up/down navigation keys. I've been able to achieve this using some basic CSS:

.parent{
    position: relative;
    width: 300px;
    height: 150px;
    border: 1px solid black;
    overflow: hidden;
}

.child{
   height: 150px;
   width: 318px;
   overflow-y: scroll;
}

img {
    width: 318px; 
}

Everything works perfectly in Webkit browsers, but in Firefox, although scrolling via mouse wheel works, pressing the up/down keys does not work. Does anyone know how to fix this issue in Firefox?

Answer №1

The issue is with the focus flag (Reference Here) of the div.

To ensure that the div receives focus when clicked, you need to assign it a tabindex. The choice between using a negative, zero, or positive tabindex depends on your specific requirements.

If the value is a negative integer, the user agent will set the element's tabindex focus flag but prevent sequential focus navigation to it.

If the value is zero, the user agent sets the element's tabindex focus flag, allows for sequential focus navigation, and follows platform conventions for determining relative order.

If the value is greater than zero, the user agent sets the element's tabindex focus flag, enables sequential focus navigation, and includes the element in the sequential focus navigation order.

To make your example work, simply add:

<div class="child" tabindex="0">
   ...
</div>

Demo Fiddle: http://jsfiddle.net/abhitalks/y1boh9v7/3/

This solution should function correctly across all browsers (tested on IE-11, GC-39, and FF-34).


Below is an excerpt showcasing a method to hide scrollbars. You can hide scrollbars completely by increasing padding, although this example keeps them visible for simplicity. If you choose to hide scrollbars, provide an alternative scrolling mechanism like mouse-based drag-to-pan functionality using JavaScript.

In this snippet, the image pans when clicking the scrollbars, clicking the image and navigating with arrow keys, or touch-sliding.

Snippet:

div.scrollParent {
    height: 240px; width: 240px;
    border: 1px solid #eee;
    overflow: hidden;
}
div.scrollChild {
    height: 240px; width: 240px;
    padding: 0px 12px 12px 0px;
    overflow: auto; 
}
img { display: block; }
<div class="scrollParent">
    <div class="scrollChild" tabindex="0">
        <img src='http://lorempixel.com/320/320' />
    </div>
</div>

.

Answer №2

It seems that the issue arises because Firefox does not automatically focus on the .child element when clicked. A workaround for this is to use JavaScript:

$(function() {
    $('.child').on('click', function(e) {
        $('.child').focus();
    });
});

By clicking inside the child element, it will gain focus and allow you to navigate with the arrow keys.

Check out the demo here: http://jsfiddle.net/c11khcak/14/ (tested in Firefox 36.0a2)

Answer №3

To achieve this functionality, follow the steps below:

HTML (to enable key operations when div is clicked/focused)

<div class="child" tabindex='1'>

CSS

.parent{
  position: relative;
  width: 300px;
  height: 150px;
  border: 1px solid black;
  overflow: hidden;
}
.child{
  overflow-y: scroll;
  position:absolute;
  top:0; right:-18px; left:0; bottom:-18px;
}

img {
  width: 318px; 
  vertical-align:bottom;
}

Check out the demo page

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

Unable to load JQuery from a div element

My goal is to create a standard .html file containing the navigation, footer, and other elements that will be used across multiple pages for a small site I'm building. I want to keep it simple and avoid using php or other programming languages. I&apo ...

When sorting items, the page automatically jumps to the top of the screen

I have been working on creating a sortable portfolio using jQuery. One issue I am facing is that every time I click on a filter for the portfolio items, the page automatically scrolls to the top. Is there a way to prevent this from happening? You can vi ...

Is it possible to display this code through printing rather than using an onclick event?

I have a puzzle website in the works where users select a puzzle to solve. I am looking for a way to display the puzzles directly on the website instead of using pop-up boxes. I am proficient in various coding languages, so any solution will work for me. ...

Avoiding Page Reloads with Ajax while Removing Entries from a Table in Laravel

I am encountering an issue where I can click the button, but it requires a refresh to execute the delete action. Is there something in my ajax code causing this problem and why is it refreshing? I want the button to instantly delete without the need for a ...

Managing the width of an HTML table column based on its text content dynamically

Here is an example of an html table : <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="480px" class="societe" ><div style="float:left;font-size:12px;padding-top:2px" ><?php echo $_SESSION ...

Using JavaScript and jQuery to create a delay when handling input events

I am working on a project where I have an HTML table that retrieves its values from a database using jQuery Ajax. Here is an example: <div id="tableId"></div> Below is the JavaScript code: function showUser(rowsToShow) { request = $.get("s ...

Error encountered in Django when attempting to pass an SQL query due to an UnboundLocalError

When I encountered an issue: Environment: Request Method: POST Request URL: http://127.0.0.1:8000/mainpage.html Django Version: 3.2.12 Python Version: 3.7.4 Installed Applications: ['django.contrib.admin', 'django.contrib.auth' ...

Flex bug in safari causing issues with inline form display

I have created a simple inline form using flexbox. However, I encountered an issue in Safari where the button loses its width. Here is a screenshot for reference: https://i.stack.imgur.com/3s5AR.jpg Interestingly, the form looks fine in all other browsers ...

Saving the subtracted value from a span into a cookie until the checkbox is unchecked - here's how to

I am working on a piece of code that includes numeric values within a span. When the checkbox is clicked, it subtracts 1 from the main value, essentially reducing the total value. How can I achieve this so that even after the form is submitted, the deducte ...

Tips for utilizing ion view within an ionic 2 application

In my original use of Ionic 1, I placed the footer after the <ion-content> and before . However, in the new Ionic 2, I can't seem to find any reference to <ion-view>. My specific need is to have two buttons at the bottom of the screen fol ...

Unique CSS content for varied designs

I have a CSS code snippet for a tooltip: .GeneralTooltip { background:#c7430f; margin:0 auto; text-transform:uppercase; font-family:Arial, sans-serif; font-size:18px; vertical-align: middle; position:relative; } .GeneralTooltip::before { content:"This is ...

Extracting precise information from HTML documents

Looking to extract specific data from an HTML file using C# and HtmlAgilityPack. Here is a snippet of the HTML: <p class="heading"><span>Greeting!</span> <p class='verse'>Hi!<br> // Hello!</p>& ...

org.openqa.selenium.WebDriverException: Unable to establish a new session: Unable to locate: Capabilities {acceptInsecureCerts: true using Firefox

Running Windows 10 - 64 with Firefox 61.0.2 and Java installed, I am currently conducting tests using selenium-grid along with selenium-server-standalone-3.11.0.jar, and geckodriver 21.0. However, upon running the test, an error message is displayed: or ...

How can I attach :after and :before pseudo-elements to a submit button?

I'm attempting to enhance my submit button with :after/:before elements, but I'm having trouble getting it to work properly. Specifically, I want to add a swipe (Sweep To Right) transition effect on the button from left to right. Similar to - th ...

Angular - Customizing button bindings for various functions

As a newcomer to Angular and TypeScript, I am faced with the task of creating a customizable button that can display text, an icon, or both. For example: button-icon-text-component.html <button> TEST BUTTON </button> app.component.html & ...

Developing 2 potential results from textarea input using NODE.JS and HTML

Today, I encountered an issue while working on my bot website project that responds to textarea input. When I attempted to test it with two different commands, one of the commands stopped working unexpectedly. I'm puzzled by this and would greatly app ...

The process of running npx create-react-app with a specific name suddenly halts at a particular stage

Throughout my experience, I have never encountered this particular issue with the reliable old create-react-app However, on this occasion, I decided to use npx create-react-app to initiate a new react app. Below is a screenshot depicting the progress o ...

Disable the click event using jQuery

$("button").click(function (){ $("<button>Start</button>).appendTo('main'); }); The code above introduces a functionality where clicking a button generates another button dynamically. However, each subsequent click kee ...

Ways to correct inverted text in live syntax highlighting using javascript

My coding script has a highlighting feature for keywords, but unfortunately, it is causing some unwanted effects like reversing and mixing up the text. I am seeking assistance to fix this issue, whether it be by un-reversing the text, moving the cursor to ...

Guide on updating a table row upon clicking the edit button in an Angular 12 template-driven form

Currently, I have set up a table where the data can be edited by clicking on a hyperlink and then saving the changes with a button. The issue I am facing is that when I click on the edit link, all rows become editable instead of just the specific row I cli ...