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

Do JavaScript functions operate synchronously or asynchronously?

Here is the JS code snippet I am working with: <script> first(); second(); </script> I need to ensure that second() will only be executed after first() has completed its execution. Is this the default behavior or do I need to make any modific ...

Eliminating the vertical scroll on a webpage with the help of Bootstrap 5's responsive design capabilities

I've been tasked with converting a Figma design into an HTML page using Bootstrap 5. Take a look at the Figma design: https://i.sstatic.net/jo5Si.png However, there's an issue causing a vertical scroll bar to appear on the page. The culprit see ...

Vue.js: Issue with applying class binding while iterating over an object

I've been working with an object data that looks like this: object = { "2020092020-08-01":{ "value":"123", "id_number":"202009" }, "2020092020-09-01":{ "value& ...

A curated collection saved in LocalStorage using React JS

I have implemented a LocalStorage feature to create a favorite list, but it only adds one item each time the page is reloaded. The items are retrieved from a JSON file. For a demonstration of how my code functions, check out this link: const [ storageIte ...

Using a Second List Element in CSS Image Rollover Map with jQuery

I have been utilizing this interactive map from Wolf's website, but I am interested in incorporating a secondary list of countries alongside the existing one as the base for the script. However, due to presentation reasons, the second menu cannot resi ...

Strange spacing in Angular Material checkbox

I have a container with an angular material checkbox inside. The background of the container is black, so I changed the background color of the checkbox to white for visibility. However, there seems to be some unwanted spacing on the right side of the chec ...

Encountering difficulties in populating mongoose document following a model query

Hi everyone, this is my first time posting on SO so I'm hoping for some positive outcomes. I've been using Mongoose in a current project without any issues until now. The problem arises when trying to populate object references after querying fo ...

Uncovering the inherent worth of an item pulled from a remote location using Vue.js

Currently, I am retrieving a list of countries by making an API call in VueX. The fetched data is then stored in a state using a mutation. Essentially, the countries are saved in a variable known as this.$state.getters.countryList, which can be accessed f ...

What could be causing Mathjax to generate multiple copies?

I have integrated MathJax into my application to render MathML. The code snippet below is used to ensure that the MathML is typeset properly: $rootScope.$watch(function() { MathJax.Hub.Queue(["Typeset", MathJax.Hub]); return true; }); However, I ...

Using ng-init to pass a JSON object

I'm attempting to pass a JSON Object to my application using ng-init and the stringify method, but I am encountering an error. Instead of working as expected, I am getting a Lexer error. Lexer Error: Unexpected next character at columns 8-8 [#] in ex ...

Unable to get ajax Post to function properly

Looking to save an object on a restful server, I attempted using an HTML form which worked fine. However, when trying it with JavaScript, I encountered some issues. Here's the code snippet: var app2={"user_id" : seleVal, "name":nome2, "img":img2, "ty ...

My preference is for the flex box to expand in width (sideways) without increasing in height (up and down)

Is there a way for flex items to expand in width but only in height when necessary? I enjoy using flexbox, but I find it frustrating that all flex items in a row grow to the same height even when there isn't enough content to fill them, resulting in a ...

Changing the style of a single element in various components in Vue

I need to alter the design of a specific div that is used in different components within my Vue.js application. The #app div should have a padding of 172px only in the Hello.vue component, while it should remain at 0px in all other components. Is there a w ...

Using React hooks to update the state of an array from one component to another

I am currently working on a MERN blog website project and I've encountered an issue while trying to update comments on a post. I'm editing the comment from another component but facing difficulty in updating the state after making changes. Would ...

Utilize Jquery to insert new text into a textbox and then organize the contents of the textbox using Jquery

Currently, I am utilizing the ASP.NET asp:checkboxlist control which consists of 36 listitems, displaying 36 checkboxes. The HTML representation resembles a table format. My goal is to dynamically add checked items in this div in a sorted manner. Additiona ...

Show information according to the selection made in the dropdown menu

Greetings! I am currently developing a web app using MVC .NET (C#) that includes a registration page for two types of users, type 1 and type 2. In the form, there is a dropdown list where users can select their type. When selecting type 2, I would like t ...

Fluctuating price depending on the selected choice

Hello, I am in the process of updating the price based on the selection made from the options. I am unsure whether to use JavaScript or Ajax for this task and how to go about it. Can someone please guide me? <tr> <td width="160">Price:</td ...

Tips and tricks for seamlessly aligning a specific section of your webpage to ensure it scrolls smoothly into view

My codes are not being centered when I use smooth scrolling on a specific section of a Bootstrap carousel template. Is there an easier way to achieve this? The explanation in a post from six years ago didn't help much. Here are my codes and screenshot ...

Removing an item from a React (Hooks) array state: A step-by-step guide

In my code, I have a list of text inputs populated from an array and I am trying to delete a specific element based on its index. The issue I am facing is that even though the console log correctly shows the updated array without the removed element, visua ...

How can a 'complete' event listener be executed for a custom function in JQuery/JavaScript?

Here is the code snippet I'm working with: $('.fblikes span').fblikecount(); $.fn.fblikecount = function(){ //Perform JSON XHR operations to retrieve FB like counts and update the page numbers } This code will cycle through all insta ...