Click event Disable, double click event Jump

Source: Internet
Author: User

Responsive web-Design:

On the mobile side, usually the navigation menu is double-clicking the Jump page, and clicking the event shows only the level two list.

$ ("a"). Click (function () {
if (restriction condition) {
if ($ (this). Siblings ("ul"). Length! = 0) {
return false; There is a level two menu to disable jump
}
}
});
$ ("a"). DblClick (function () {
Window.location.href = $ (this). attr ("href"); Double-click Jump
});

Example

<! DOCTYPE html>

<meta charset= "UTF-8" >
<title></title>
<style>
. menu {
Display:none;
}
</style>

<body>
<ul class= "Main-menu";
<li>
<a href= "http://www.baidu.com" > Level menu </a
<ul class= "menu",
<li>
<a href= "http://www.weibo.com" > Level two menu </a>< br> </li>
</ul>
</li>
<li>
<a href= "http://www.baidu.com" > First level menu </a>
</li>
<li>
<a href= "http://www.baidu.com" > Level menu </a>
</l     I>
<li>
<a href= http://www.baidu.com > Level menu </a>
</li>
<li>
<a href= "http://www.baidu.com" > Level menu </a>
<ul class= "menu";
<li>
< ; a href= "http://www.weibo.com" > Level two menu </a>
</li>
</ul>
</li>

</ul>
<script src= "Https://code.jquery.com/jquery-3.1.1.min.js" ></script>
<script>
$ (function () {
$ ('. Main-menu '). Children ("Li"). each (function () {
$ (this). Find ("a"). Hover (function () {
$ (this). Siblings (". Menu"). Show ();
}, function () {
$ (this). Siblings (". Menu"). Hide ();
});
})

$ ('. Main-menu '). Children ("Li"). each (function () {
/* Click Disable */
$ (this). Children ("a"). Click (function () {
if ($ (window). Width () <= 768) {
if ($ (this). Siblings (". Menu"). Length! = 0) {
return false;
}
}
});
/* Double-click Jump */
$ (this). Children ("a"). DblClick (function () {
Window.location.href = $ (this). attr ("href");
});
});
});
</script>
</body>

Click event Disable, double-click event Jump

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.