Mobile phone-side touch event jquery Simulation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.