Ontouchstart realization of hover effect in touch screen of mobile phone
Ontouchstart realization of hover effect in touch screen of mobile phone
Recently has been doing mobile site projects, will often encounter mobile phone screen touch no interaction effect, today in an article to see the simulation of the end of the page hover effect of the example to take out and everyone to share, has been using the effect is good, we can according to the following case study:
First, CSS style:
<style type= "Text/css" >
. inner {width:100%; height:100px; position:relative;}
. Inner a {background: #000; display:block; color: #fff}
. inner A.hover {background:red;-webkit-tap-highlight-color:rgba (255,0,0,0);/* Cancel default phone Click the gray box */}
</style> II, JS code <script type= "Text/javascript" src= "/js/jquery-1.7.1.min.js" ></script>// Refer to the jquery framework <script type= "Text/javascript" >
Please choose to quote jquery
$ (function () {
$ (". Inner a"). attr (' Ontouchstart ', ' hover (this) ');//hover effect
$ (". Inner a"). attr (' ontouchend ', ' mouseout (This) ');//sec except hover
})
function Mouseout (obj) {
var className = "hover";
var _ecname = Obj.classname;
if (_ecname.length = = 0) return;
if (_ecname = = ClassName) {
Obj.classname = ""; return;
}
if (_ecname.match (New RegExp ("(^|\\s)" + ClassName + "(\\s|$)")))
Obj.classname = _ecname.replace ((New RegExp ("(^|\\s)" + ClassName + "(\\s|$)"), "");
}
function hover (obj) {
if (!obj) return;
var className = "Hover"
var _ecname = Obj.classname;
if (_ecname.length = = 0) {
Obj.classname = Classname;return;
}
if (_ecname = = ClassName | | _ecname.match (New REGEXP ("(^|\\s)" + ClassName + "(\\s|$)"))
Return
Obj.classname = _ecname + "" + className;
}
</script> page Tag Code <div class= "inner" ><a href= "#" >ontouchstart to achieve the hover effect in the touch screen of the phone, please test the results on the home page </a ></div>
Mobile phone-side touch event jquery Simulation