Change the hover effects on the desktop to be more mobile-friendly

In my desktop version, I have implemented some code that enables hovering over a button to display additional information or text. How can I modify this for mobile so that nothing happens when the button is tapped on?

.credit:hover .credit-text,
  .credit-ba:hover .credit-text {
     display: block;
  }

Instead of the hover effect, I would like to use JavaScript to make the icon clickable - toggling between hiding and showing the content upon clicking the icon. The issue with the hover click on mobile devices is that users have difficulty closing the tab by clicking around the screen instead of the button/icon itself.

.hideElement {
         display: none;
      }

Below is the JavaScript code:

const creditIcon = document.querySelector('.credit-icon');
const creditText = document.querySelector('.credit-text');

let creditOpen = false;
   creditIcon.addEventListener('click', () => {
      creditText.style.display = "block";
      creditOpen = processMenu.classList.contains('hideElement')
   })

The corresponding HTML code:

<div class="credit black-text">
               <button class="credit-icon"> (...)
               </button>
               <div class="credit-text hideElement">
                  <p>
                     Thank you
                     to my team of helpers
                     <br><br>
                     and the following
                     <br><br>
                     Collaborators<br>
                     Handmade Staples Details produced by Mary Chan
                     <br>Knitwear produced by Elaine Lip
                     <br>Shoes Handcrafted by Doyeon Ji
                     <br>Soundtrack composed by Zacharias Wolfe
                     <br><br>
                     Look Book
                     <br>Photographed by Dean Hoy
                     <br>Make Up by Ana Takahashi
                     <br><br>
                     Show
                     <br>Hair by L’Oréal Professionnel
                     <br>Make Up by MAC Cosmetics
                     Supported by ThreeUK
                     <br><br>
                     Models
                     <br>Jina Yoo
                     <br>Aaron Wong
                     <br>Reign Charbit
                     <br>Karen Reichelt
                     <br>Harrison Chan
                     <br>Jessica Chen
                     <br>Kristianna Peel
                     <br>Trinity Mcintosh
                     <br><br>
                     Special thanks to Lane Crawford
                     <br>
                     and the MAFCSM team</p>
               </div>
            </div>

Answer №1

Check out this media query suggestion

@media not all and (pointer: coarse) {
.credit:hover .credit-text,
  .credit-ba:hover .credit-text {
     display: block;
  }
 }

const creditIcon = document.querySelector('.credit-icon');
const creditText = document.querySelector('.credit-text');

let creditOpen = false;
   creditIcon.addEventListener('click', () => {
      creditText.style.display = "block";
      creditOpen = processMenu.classList.contains('hideElement')
   })
@media not all and (pointer: coarse) {
.credit:hover .credit-text,
  .credit-ba:hover .credit-text {
     display: block;
  }
 }
  
  .hideElement {
         display: none;
      }
<div class="credit black-text">
               <button class="credit-icon"> (...)
               </button>
               <div class="credit-text hideElement">
                  <p>
                     A huge thank you
                     to my amazing team
                     <br><br>
                     as well as our talented
                     <br><br>
                     Collaborators<br>
                     Handmade Staples Details produced by Mary Chan
                     <br>Knitwear produced by Elaine Lip
                     <br>Shoes Handcrafted by Doyeon Ji
                     <br>Soundtrack composed by Zacharias Wolfe
                     <br><br>
                     Look Book
                     <br>Photographed by Dean Hoy
                     <br>Make Up by Ana Takahashi
                     <br><br>
                     Show
                     <br>Hair by L’Oréal Professionnel
                     <br>Make Up by MAC Cosmetics
                     Supported by ThreeUK
                     <br><br>
                     Models
                     <br>Jina Yoo
                     <br>Aaron Wong
                     <br>Reign Charbit
                     <br>Karen Reichelt
                     <br>Harrison Chan
                     <br>Jessica Chen
                     <br>Kristianna Peel
                     <br>Trinity Mcintosh
                     <br><br>
                     Special thanks to Lane Crawford
                     <br>
                     and the MAFCSM team</p>
               </div>
            </div>

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

Is there a way to adjust the position of the scrolling bar to be closer to the post area?

I was exploring this page (http://noahsdad.com/state-fair-texas-2011/) and noticed a scrolling sidebar to the left of the content area. I'm looking to adjust it so that it is closer to the content area. Any suggestions on how to achieve this? Thank y ...

Error: Unable to access the property 'existsSync' since it is undefined - Creating Web Applications using Node.js and Express.js by Ethan Brown - Chapter 13

I am brand new to GitHub and the MEAN (mongodb, express, angular, node.js) stack. I am currently working through a book by Ethan Brown called 'Web Development with Node and Express', and he has provided a Git repository for me to clone and follow ...

I am currently having issues with a PHP script I wrote for sending email, as it is

After creating a form and implementing a PHP script to send an email upon form submission, I encountered an issue where the "Thank you" message was displayed on a different HTML page, but the email wasn't sent to my account. I uploaded the files to t ...

What is the best way to insert a variable URL in JavaScript code?

When working with PHP, I often create a declaration similar to the following (taken from an example on Stack Overflow): <script type="text/javascript"> var templateurl = "<?php bloginfo('template_url') ?>"; </script> Subse ...

Error in Node.js: The res.send method is undefined

I'm having some issues with my first attempt at creating a simple Counter Strike API bot using nodeJS. The problem lies with the res.send function, as I keep getting an error message saying "res.send is not a function" every time I try to use it. Movi ...

Scrolling text box utilizing Jquery

Currently, I am utilizing a scrolling box that functions well * view here * under normal circumstances. However, when there is an extensive amount of content below it, such as: <article class="content"> ...

Tips for implementing simple custom styling within an Angular application without relying on innerHTML

Seeking advice on the best practices for a specific scenario. I am currently developing a small Angular application where users can input text. I would like to allow them to easily make certain words bold or create links. For example, if they type *whatev ...

Utilize user input to fetch data from an external API

Let's say there is a field for 'part number' input that is not enclosed in a form tag. Whenever a user enters a value, the onblur event or a button positioned next to the input field should trigger a query to an external site via its API and ...

How can I position four DIV elements to the right of each other inside a parent DIV?

I am attempting to align 4 divs next to each other within a parent div at specific positions. The proposed div structure is as follows (referred to as the maindiv): <div> <div>1</div> <div>2</div> <div>3< ...

Tips on dynamically looping the formcontrolname and implementing validation strategies

Looking for a way to validate multiple looping of dynamic formControlName="xxx" in select field. Check out my HTML code: <ul *ngFor="let detaillist of stressli.stresstabdetails;"> <li> <div class="form-container"> ...

What is the best way to reach nested iframes?

I am looking for a solution to send post messages (window.postmessage) to iframes. Currently, it is functioning properly with a single iframe inside the parent page. However, I want it to also work for nested iframes. Here are the criteria: I should on ...

Include CLI input into JavaScript variable within the Webpack build process

I am currently attempting to incorporate a variable into my app.js file during the build process. For instance: //app.js var myvar = {{set_from_cli}}; Afterwards, I would like to execute something such as webpack -p --myvar='abc' which would pr ...

What is the best way to obtain the id of a selected row using JavaScript?

I'm attempting to utilize the JavaScript function below to extract a specific cell value from a jqgrid upon clicking. Within the following function, #datagrid refers to the table where the jqgrid is located. $("#datagrid").click(function ...

Choosing all components except for one and its descendants

I am searching for a method to choose all elements except for one specific element and its descendant, which may contain various levels of children/grandchildren or more. What I'm trying to accomplish is something like... $("*").not(".foo, .foo *").b ...

Spacing between table cells is only applied to the first row and footer

In an attempt to add spacing between the first row, second row, and footer of a table, I have experimented with cell spacing combined with border-collapse. However, the spacing is being applied all over the table instead of in specific areas. I am utilizin ...

Error Occurs While Getting Request Parameters with Ajax Post and Express.js

When utilizing ajax to send data from a JavaScript frontend to an Express.js backend server, I am having trouble retrieving the posted data in the API method of my express.js. Below is the code where I attempt to parse the request data. Your assistance i ...

The issue here is that "onreadystatechange" in JS Ajax is not defined, even

For the past day, I've been struggling with this issue and going in circles. Any help would be much appreciated :-) Synopsis I'm facing a challenge with asynchronous AJAX calls to CGI using resolver and FQDN variables to obtain DNS resolution ...

Is there a way to trigger a JavaScript function once AJAX finishes loading content?

I've been utilizing some code for implementing infinite scrolling on a Tumblr blog through AJAX, and it's been performing well except for the loading of specific Flash content. The script for the infinite scroll can be found here. To address the ...

Are you in the business of building JavaScript hubs?

I have a unique setup where my express server is in charge of handling all routing and session functionalities. I've envisioned a system where logged-in users can connect to distinct "hubs" based on the location of each hub. My idea was to treat each ...

The Echart bar graph is not displaying when trying to use JSON data

Seeking assistance as a beginner in building Basic Bar inverted axes using json data. I am trying to achieve a chart similar to Bar Inverted Axes, but encountering issues with the chart not displaying properly. Utilizing Angular to develop the web applicat ...