`
天梯梦
  • 浏览: 13636888 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

jQuery: 判断指针是否在某元素内 How do I check if the mouse is over an element

 
阅读更多

代码:

// required jquery.min.js

$(function()
{ 
        var $current_tab_menu = $('#main_menu');
	$(document).on('mouseover',function(e)
	{ 
		var xx = e.originalEvent.x || e.originalEvent.layerX || 0; 
		var yy = e.originalEvent.y || e.originalEvent.layerY || 0;
		
		if($current_tab_menu && $('.has_submenu:hover').length === 0)
		{
			console.log(($current_tab_menu.is(':hover')?'Y':'N'));
			
			if($current_tab_menu.is(':hover')) $current_tab_menu.show();
			else $current_tab_menu.hide();
		} 
		else console.log('XY:'+(e.pageX + '---' + e.pageY));
	});
})

 

重点在于,判断的时候用 $('.has_submenu:hover').length === 0 代替  $('.has_submenu').is(':hover')。 原因是当你在 jQuery 1.9中使用.is(“:hover”) 的时候容易参数如下错误提示:

Error: Syntax error, unrecognized expression: unsupported pseudo: hover

 

原文/转自: jQuery: 判断指针是否在某元素内 How do I check if the mouse is over an element

 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Applied jQuery: Develop and Design

    The Author, Jay Blanchard, has practical experience working in the field and wastes no time getting to the instruction, taking the reader from a beginner to a proficient interface programmer by the ...

    《jQuery: Novice to Ninja》- 2017 英文原版

    Rich, fast, versatile — JavaScript the way it should be!... Used by over half the world’s top 10,000 websites, jQuery is the fastest, most efficient way to add killer functionality to your site.

    《jQuery: Novice to Ninja: New Kicks And Tricks》英文原版 Kindle - mobi格式

    Used by over half the world’s top 10,000 websites, jQuery is the fastest, most efficient way to add killer functionality to your site. Now in its second edition, you’ll be taken through the ...

    Code School jQuery: The Return Flight slide

    Code School jQuery: The Return Flight slide

    jquery如何判断某元素是否具备指定的样式

    如果css写成行内样式,可以通过获取style属性的值来判断,示例如下: 判断id为divid的div元素是否有font-size样式: 代码如下: ”divid” xss=removed></div> jquery代码如下: jQuery(“#divid”).each(function(){...

    jquery 滚轴 mousewheel

    jquery 滚轴 mousewheel

    jquery删除数组中重复元素

    话不多说,下面就跟着小编来看下利用jquery实现删除数组中重复元素的具体思路吧 首先定义如下数组: var arr=[0,2,3,5,6,9,2]; 我们可以看到数组中... //判断元素是否存在于new_arr中,如果不存在则插入到new_arr的

    jQuery数字跟指针时钟一体特效.zip

    jQuery数字跟指针时钟一体特效是一款带有年月日星期指针时钟数字时钟等。

    jQuery完全实例.rar

    By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression ...

    jQuery 子级元素在父级元素内滚动

    jQuery,滚动,jQuery 子级元素在父级元素内滚动

    jQuery UI Cookbook (pdf + ePub)

    You will learn how to do all these things within the context of the big picture, by finding out why the components work the way they do, making you well-versed in jQuery UI. What you will learn from...

    Sortable前端框架

    scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) { data...

    jQuery 鼠标滚轮插件 mousewheel

    1.使用方法很简单,仅仅把mousewheel绑定到指定元素上。示例代码如下: // using on $('#my_elem').on('mousewheel', function(event) { console.log(event.deltaX, event.deltaY, event.deltaFactor); }); // ...

    jquery blockUI Version 2.39

    // enable if you want key and mouse events to be disabled for content that is blocked bindEvents: true, // be default blockUI will supress tab navigation from leaving blocking content // (if ...

    jQuery- Novice to Ninja

    jQuery: Novice to Ninja will show you how to unleash the amazing power of jQuery. In this easy-to-follow guide, you'll master all the major tricks and techniques that jQuery offers-within hours.

    JQuery对元素拖拽排序,元素拖拽,JQuery拖拽Demo

    原理是用CSS中position定位来跟踪鼠标移动,就是让元素跟踪鼠标位置,然后判断其在页面显示元素列表中的像素位置,从而判断其在数据列表中的位置。 可以看到文章链接...

    jquery判断元素内容是否为空的方法 原创

    用jquery获取元素内容需要分两个情况: input 用val(); var value = $(‘#test’).val(); 是否为空的判断方法: if(value.length == 0){} 如果value为空执行的操作 if(value!=”){} 如果value不为空执行的操作 ...

    Wrox.Professional.jQuery 2012

    It is important to know how to extend the power of jQuery with custom methods as it is a fundamental skill for a top jQuery developer. Chapter 13 introduces the jQuery Deferred Object, which was ...

    jQuery.Essentials.

    It is used in over 60% of the top websites on the Internet. It was written to make DOM manipulation (so, moving things around a web page) easier for developers. It acts through JavaScript to ascribe ...

    jQuery 判断元素是否存在然后按需加载内容的实现代码

    判断网页中一个元素是否存在的方法: var $selector = $('.my-element'); if ( $selector.length > 0 ) { // 如果存在,引入jQuery库,或做其他操作 } 在这里,我们先判断一下页面是是否有 `.slideshow`,如果有,...

Global site tag (gtag.js) - Google Analytics