作者:谦谦骄子_458 | 来源:互联网 | 2023-05-18 11:54
iamtryingtomakeelementinspectorinjquery,ialsoalmostdone,butitworkssometimes(notpr
i am trying to make element inspector in jquery, i also almost done, but it works some times (not properly working). my code --->
我正在尝试在jquery中创建元素检查器,我也差不多完成了,但它有效一段时间(不正常工作)。我的代码--->
here the fiddle ---> http://jsfiddle.net/ashokdamani/01ntuu6e/
这里的小提琴---> http://jsfiddle.net/ashokdamani/01ntuu6e/
Html--->
Jquery--->
var ad_focused;
var $ad_focusedele;
var ad_mousetop;
var ad_mouseleft;
$('body').mousemove(function (eve) {
ad_mousetop = eve.pageY;
ad_mouseleft = eve.pageX;
if (ad_focused) {
if (isUnHovered($ad_focusedele)) {
$(".hoverDark").remove();
$(".hoverLight").remove();
$ad_focusedele = null;
ad_focused = false;
}
}
});
$eles = $('div, input, form').not('body > div, body > form, body > iframe');
$eles.hover(function () {
if (ad_focused)
return;
ad_focused = true;
$ad_focusedele = $(this);
var ad_wr = '';
$(this).parent().append(ad_wr);
var mleft = !isNull($(this).css('margin-left')) ? parseInt(($(this).css('margin-left')).replace('px', '')) : 0;
var mright = !isNull($(this).css('margin-right')) ? parseInt(($(this).css('margin-right')).replace('px', '')) : 0;
var mtop = !isNull($(this).css('margin-top')) ? parseInt(($(this).css('margin-top')).replace('px', '')) : 0;
var mbottom = !isNull($(this).css('margin-bottom')) ? parseInt(($(this).css('margin-bottom')).replace('px', '')) : 0;
var elemOuterWidth = $(this).outerWidth(true) - (mleft == 0 ? 0 : mleft - 5) - (mright == 0 ? 0 : mright - 5);
var elemOuterHeight = $(this).outerHeight(true) - (mtop == 0 ? 0 : mtop - 5) - (mbottom == 0 ? 0 : mbottom - 5);
var elemPos = $(this).position();
var elemPosTop = elemPos.top - 1;
var elemPosLeft = elemPos.left - 1;
$(".hoverDark").css({
"width": elemOuterWidth,
"height": elemOuterHeight,
"top": elemPosTop + (mtop == 0 ? 0 : mtop - 5),
"left": elemPosLeft + (mleft == 0 ? 0 : mleft - 5)
});
$(".hoverLight").css({
"width": elemOuterWidth,
"height": elemOuterHeight,
"top": elemPosTop + (mtop == 0 ? 0 : mtop - 5),
"left": elemPosLeft + (mleft == 0 ? 0 : mleft - 5)
});
$(".hoverDark").stop(true, true).show();
$(".hoverLight").stop(true, true).show();
});
function isUnHovered(obj) {
var eletop = $(obj).offset().top;
var eleleft = $(obj).offset().left;
var eleright = $(obj).offset().left + getCssValue($(obj).css('width'));
var elebottom = $(obj).offset().top + getCssValue($(obj).css('height'));
return !(ad_mouseleft > eleleft && ad_mouseleft eletop && ad_mousetop
I am wrapping up the element when hover and unwrapping it when mouse not moving on it (ie unhover, but not exactly unhover ,because when it wrapped with some div its loops the hover event).
当鼠标没有移动时,我在悬停和展开它时包裹元素(即,徘徊,但不是完全卸载,因为当它用一些div包裹它的循环时悬停事件)。
1 个解决方案