当前位置 : 主页 > 网络编程 > JavaScript >

js 实现 浏览器控制台 Elements 选框功能

来源:互联网 收集:自由互联 发布时间:2021-06-28
js var DomOutLine = jQuery('',{id: 'DomOutLine',style: `transition: all .2s;background:rgba(0,0,0,.5);position:absolute;z-index: 1000000;pointer-events: none;`});var DomInfo = jQuery('',{id: 'DomInfo',style: `background: #333740; position:
js
var DomOutLine =  jQuery('',{
	id: 'DomOutLine',
	style: `transition: all .2s;background:rgba(0,0,0,.5);position:absolute;z-index: 1000000;pointer-events: none;`
});
var DomInfo = jQuery('',{
	id: 'DomInfo',
	style: `
		background: #333740;
	    position: absolute;
	    z-index: 1000001;
	    pointer-events: none;
	    height: 26px;
	    border: 1px solid #fff;
	    border-radius: 3px;
	    font-size: 12px;
	    line-height: 26px;
	    color: #fff;
	    padding: 0 10px;
	    top: -26px;
	    box-sizing: border-box;
	`
});
DomInfo.appendTo(DomOutLine);
jQuery('body').append(DomOutLine);
jQuery('body').bind('mousemove',function(e){
	var d = e.target.getBoundingClientRect();
	$('#DomOutLine').css({
		bottom:d.bottom,
		height:d.height,
		left:d.left,
		right:d.right,
		top:d.top+jQuery(window).scrollTop(),
		width:d.width
	})
	var idTxt = '';
	if(e.target.id){
		idTxt = '#'+e.target.id;
	}
	var classTxt = '';
	if(e.target.classList){
		e.target.classList.forEach( function(element, index) {
			classTxt += '.'+element;
		});
	}
	$('#DomInfo').text(`${e.target.nodeName.toLowerCase()}${idTxt}${classTxt}|${d.width}x${d.height}`)
});
上一篇:js设计模式
下一篇:dom入门 private
网友评论