简体   繁体   中英

Links don't work on mobile due to Javascript hover effects

On my site I've used hover.css to add a hover animation to my nav links. For some reason, this is causing the links to not be clickable on mobile. Any ideas on how to resolve this? Here's some of my code: Here's my HTML:

<html>
<head>
<link rel="stylesheet" type="text/css" href="sss.css">
<link rel="stylesheet" type="text/css" href="sss2.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Oxygen:300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans&subset=latin,latin-ext' rel='stylesheet' type='text/css'>

<script src="sss.min.js"></script>
<script>
jQuery(function($) {
$('.slider').sss();
});
</script>
<div class="links">
<center>

<h>&nbsp;Sophie Calhoun </h>&nbsp;&nbsp;
<a href="http://www.sophiecalhoun.com/" class="hvr-grow"> &nbsp;home&nbsp; </a>&nbsp; 
<a href="http://www.sophiecalhoun.com/design.html" class="hvr-grow"> &nbsp;design work&nbsp; </a>&nbsp; 
<!-- <a href="http://www.sophiecalhoun.com/illustration.html" > &nbsp;illustration </a><p> &nbsp;<p> --!>
<a href="http://www.sophiecalhoun.com/motion.html" class="hvr-grow"> &nbsp;motion graphics&nbsp; </a> &nbsp;
<a href="http://www.sophiecalhoun.com/interactive.html" class="hvr-grow"> &nbsp;interactive&nbsp; </a>&nbsp; 
<a href="http://www.sophiecalhoun.com/resume.html" class="hvr-grow"> &nbsp;resume&nbsp; </a>  &nbsp; &nbsp;</center></div></div>
<!--etc.--!>

And here's the CSS modifying the hvr-grow property:

.hvr-grow {
  display: inline-block;
  vertical-align: middle;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: transform;
  transition-property: transform;
}

.hvr-grow:hover, .hvr-grow:focus, .hvr-grow:active {
  -webkit-transform: scale(0.95);
  transform: scale(0.95);
}

I'd like to know if I can disable this effect on mobile or somehow make the links work with the effect. Thanks!!

I'm not able to test your css on a mobile device right now, but if you just wanted to disable the effect, you could wrap the css in a media query so that it is only used on larger screen sizes.

@media (min-width: 600px) {
    /* Your css here */
}

You can try doing a user agent test to detect mobile browsers.

Check out this site: http://detectmobilebrowsers.com/

Or do something like this:

if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
 $('.hvr-grow').removeClass('hvr-grow');
}

Use .hvr-grow only for animations so you don't have the issue with the links dissappearing, like this:

<a href="http://www.sophiecalhoun.com/" class="hvr-grow links"> &nbsp;home&nbsp; </a>&nbsp; 
<a href="http://www.sophiecalhoun.com/design.html" class="hvr-grow links"> &nbsp;design work&nbsp; </a>&nbsp; 

.links {
  display: inline-block;
  vertical-align: middle;
}

.hvr-grow {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: transform;
  transition-property: transform;
}

.hvr-grow:hover, .hvr-grow:focus, .hvr-grow:active {
  -webkit-transform: scale(0.95);
  transform: scale(0.95);
}

good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM