Activate touch/click hover functionality on mobile devices

On the desktop view, everything is working as expected except for the DIV that appears on hover. It doesn't show in mobile view. I would like to make it appear on touch/click on mobile or tablet devices.

I have tried using :active after :hover based on some suggestions, but that did not work.

I am open to solutions involving JavaScript or jQuery as well.

DEMO: https://jsfiddle.net/ovg6xzhu/

HTML:

<div class="hoverEffect hoverEffect-first">
  <img src="https://via.placeholder.com/150" />
  <div class="mask">
    <h2>Web Services!</h2>
    <p>We are going to build another sets of css hover image effects with CSS3 animations.<br /><a href="#">View All</a></p>
  </div>
</div>

CSS:

.hoverEffect {
  width: 100%;
  float: left;
  overflow: hidden;
  position: relative;
  text-align: center;
  cursor: default;
  border-radius: 2px;
  margin-bottom: 30px;
}
.hoverEffect .mask {
  width: 100%;
  position: absolute;
  overflow: hidden;
  top: 0;
  left: 0
}
.hoverEffect img {
  display: block;
  position: relative
}
.hoverEffect h2 {
  text-transform: uppercase;
  color: #fff;
  text-align: center;
  position: relative;
  padding: 10px;
  margin: 20px 0 0 0
}
.hoverEffect p {
  position: relative;
  color: #fff;
  padding: 0px 20px 20px;
  text-align: center
}
.hoverEffect-first img {
  transition: all 0.2s linear;
  width:100%;
  height:auto;
}
.hoverEffect-first .mask {
  opacity: 0;
  background-color: rgba(61, 90, 128, 0.95);
  transition: all 0.4s ease-in-out;
  width: 100%;
  height: 100%;
}
.hoverEffect-first h2 {
  margin: 10px 40px;
  transform: translateY(-100px);
  opacity: 0;
  transition: all 0.2s ease-in-out;
}
.hoverEffect-first p {
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.2s linear;
}
.hoverEffect-first:hover img, .hoverEffect-first:active img {
  transform: scale(1.1);
}
.hoverEffect-first:hover .mask, .hoverEffect-first:active .mask {
  opacity: 1;
}
.hoverEffect-first:hover h2,
.hoverEffect-first:hover p,
.hoverEffect-first:active h2,
.hoverEffect-first:active p {
  opacity: 1;
  transform: translateY(0px);
}
.hoverEffect-first:hover p, .hoverEffect-first:active p {
  transition-delay: 0.1s;
}
.hoverEffect-first:hover a.info, .hoverEffect-first:active a.info {
  transition-delay: 0.2s;
}

Answer №1

Your solution is effective. Remember to regularly clear your browser cache for optimal performance. A simple tip for mobile users is to append "/?random" at the end of the URL for a fresh page load. Customize the word "random" to ensure a unique reload each time. I also agree with ehab's suggestion that hiding content on hover may not be user-friendly on mobile devices. Consider using visual cues like buttons or allowing animations to happen naturally as the content comes into view.

Answer №2

Using CSS alone should suffice for achieving this goal; there is no need for JavaScript. The code you provided appears to be functioning correctly, so the issue may have been related to a cache problem. However, it's worth noting that emulating hover effects on mobile devices is not advisable as it can lead to a suboptimal user experience. Mobile users may not expect to have to click to trigger an effect, especially if they then need to click on another element to undo it.

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

The CORS policy has blocked access to XMLHttpRequest at 'http://localhost:8080/' from the origin 'http://localhost:3000'

There seems to be an issue with the CORS policy blocking access to XMLHttpRequest when trying to send a post request from NuxtJS frontend to a Node server hosted on localhost:3000. Despite using CORS in the app, the error persists, preventing insertion of ...

Tips for toggling helper messages during form validation using AngularJS

I've integrated ngMessages into my AngularJS application for form validation, and it has been quite helpful. However, I've encountered a challenge that I can't seem to figure out. For example, consider the following code snippet within my F ...

Exploring the process of incorporating a JavaScript library into an Angular project

I've encountered this issue before and know there are various workarounds available. I often search online for front-end design code to enhance the user experience of my projects, such as carousels, animations, and more. However, most of these project ...

Incorporate a personalized JavaScript code segment during the Vue build process

I am currently working with Vue CLI and I need to include a custom javascript section in the default template when I release my project. However, I do not want this section to be included during the debugging phase. For example, I would like to add the fo ...

Ensure that you do not repeat the same action

In my application built on Node.js, I am utilizing Express for API routes and MongoDB as the database. One of the functionalities includes a raffle where users should only be able to enter once. Currently, I am storing participant information in an arra ...

On Chrome, everything looks good but on Firefox, my footer is mysteriously disappearing. No matter how much padding I

One of my wrapper divs has padding-bottom:40px; to show the position absolute "designed by" text at the bottom of the page. In Chrome, everything works as expected. However, in Firefox, the padding-bottom doesn't seem to have any effect and the wrapp ...

AngularJS implemented to trigger a popup alert after a certain duration of time has elapsed since the

Can we create a popup alert that says "Error Contacting Server" when the http request does not receive any response? .controller('items_ctrl',['$scope','$http',function($scope,$http){ $scope.shop_id=localStorage.getItem(" ...

The email sending feature of the ajax jquery form has unexpectedly ceased functioning

I'm encountering an issue with a form that was previously able to send emails from the server, but suddenly stopped working. I'm having trouble identifying the cause of the problem. Interestingly, when I use the form without ajax, the email funct ...

Updating the unordered list (UL) of rows in MySQL dynamically

Currently working on a test site that aims to function as a video playlist player pulling videos from the VIMEO API based on URL numbers (like vimeo.com/7100569) The setup involves storing a list of these URLs in a MySQL table. At this stage, I have manag ...

What is the best way to show a list when hovering the mouse over a

<nav> <a href="login.html" class="dropdown-content" style="text-align: center"><span id="login">您好</span><i class="login"></i></a> <a href="9.html"><i class="like"></i></a> <a href="7 ...

Add a variable to the configuration

Here is my configuration setup angular.module('moduleApp.config') .config(['$translateProvider', '$languageSupportProvider', function($translateProvider, $languageSupportProvider) { // Need to access data from myS ...

What is the best way to submit a form in jQuery without causing the page to refresh?

I am trying to create a form that can be submitted without refreshing the page using jQuery. The information from the form should then be posted to actions.php. Could someone please assist me with this? <div id="postbox"> <form method="post" ...

Printing paths of nested options is incomplete

Is there a way to display the full path of a select with nested options in angular? When I click on an option, currently it only shows the option value. <select> <optgroup label="A"> <option>1</option> <optio ...

Differentiate among various forms of beforeunload occurrences

Can JavaScript differentiate between beforeunload events triggered by a user closing a browser tab versus clicking a mailto link? I am looking to achieve the following: window.addEventListener("beforeunload", function (e) { if(browserTabClosed) { ...

Ways to completely obliterate a datatable?

Currently, I am utilizing datatables in conjunction with bootstrap-daterangepicker to set a range for displaying data in Datatables. Everything is functioning correctly so far. However, the issue arises when I choose a new range in daterangepicker, it of ...

Steps for Setting a Radio Button Group back to a Specific Value

I am currently working with a set of radio buttons that are displayed using ng-repeat. The last radio button is selected by default (ng-checked="$last"): Status: <span ng-repeat="button in statusList"> <input type="radio" name="status" ng-mod ...

Ways to streamline your Jquery/Ajax code: Eliminate repetitive sections

Seeking guidance on optimizing my Jquery/Ajax code that involves sending GET requests. I've noticed there's quite a bit of repetition. How can I streamline this code effectively? $(".add_to_cart").click(function() { product_slug = $(this).at ...

Mysterious jQuery feature: Transform your top slider to slide in from the right side

My expertise lies in web design using Photoshop, while other programmers bring my designs to life. However, I've been considering taking on the coding part myself for a change with jQuery being outside of my comfort zone. This is my first project in w ...

Understanding setInterval and clearInterval in Vue.js 3: A Complete Guide

I am currently developing an application that relies on a timer to update variables every second. The implementation involves using the "setInterval" function to initiate the timer and the "clearInterval" function to halt it. However, I feel like my curren ...

How does the call method on array.prototype.includes work with arguments x and y?

Curious about the functionality of array.prototype.includes.call(x, y);. Discovered that includes() confirms if an array has the specified value and provides a true or false result. Learned that call() invokes this alongside any optional arguments. The ...