Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome inspect element using jquery

i wanted to create somthing similar to the inspect dom feature in chrome's devtools which when onhover a - preset list of doms - a div.shadow is created on top of the dom with the same width/height covering it,and when mouse leave shadow its hidden or in case a new selected dom is hovered it changes place and dimensions,

dom.mouseover(function(e) {
  shadow.css({
    display: "block",
    width: dom.width+"px",
    height: dom.height+"px",
    top: dom.top+"px",
    left: dom.left+"px"
  });
});

shadow.mouseleave(function() {
  $(this).css('display', 'none');
});;

but the problem arise when having parent/children in the selected dom lists like "body" where it put the shadow on the body but then ignore any mouseover/mouseenter from childrens

like image 836
Tarik Avatar asked Sep 14 '13 18:09

Tarik


People also ask

Does jQuery work in chrome console?

It may take a bit of time for jQuery to load. But, once jQuery is loaded, you can run your custom jQuery functions in chrome console. There may be some conflicts with other jQuery versions that may have been loaded on the page.

What is $() in jQuery?

In the first formulation listed above, jQuery() — which can also be written as $() — searches through the DOM for any elements that match the provided selector and creates a new jQuery object that references these elements: 1. $( "div.


1 Answers

Tested and fully working

var shadow = $('<div></div>').css({background: 'rgba(100,0,0,0.5)', position: 'absolute'}).appendTo('body');
$(document).on('mousemove', function(e) {
    shadow.hide();

    var x = e.clientX, y = e.clientY,
        dom = $(document.elementFromPoint(x, y));

    if(dom.length < 1)
        return;

    shadow.css({
        display: "block",
        width: dom[0].offsetWidth +"px",
        height: dom[0].offsetHeight +"px",
        top: dom.position().top +"px",
        left: dom.position().left +"px"
   });

   shadow.show();
});
like image 170
Jakub Michálek Avatar answered Sep 30 '22 08:09

Jakub Michálek