Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

measure width in px chrome extension

var fromX, fromY;
var svg = document.createElementNS ('http://www.w3.org/2000/svg',"svg");
svg.setAttribute("style", "position: absolute; top:0;left:0;height: " + document.body.clientHeight + "px;width: 100%");
var line = document.createElementNS('http://www.w3.org/2000/svg','line');
line.setAttribute("style", "stroke-width: 4; stroke: red");

svg.appendChild(line);
document.body.appendChild(svg);

document.body.addEventListener("mousedown", function (e) {
  fromX = e.pageX;
  fromY = e.pageY;
});

document.body.addEventListener("mousemove", function (e) {
  if (fromX === undefined) {
    return;
  }

  line.setAttribute("x1", fromX);
  line.setAttribute("x2", e.pageX);
  line.setAttribute("y1", fromY);
  line.setAttribute("y2", e.pageY);

  console.log(
    [fromX, fromY], " to ", [e.pageX, e.pageY], "Distance:",
    Math.sqrt(Math.pow(fromX - e.pageX, 2) + Math.pow(fromY - e.pageY, 2))
  );
});

document.body.addEventListener("mouseup", function (e) {
  fromX = undefined;
  fromY = undefined;
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: puppeteer open browser authentication facebook 
Javascript :: redux store as number instead of string 
Javascript :: processing map in javascript 
Javascript :: email collapsible section 
Javascript :: iframe set value on input outside js 
Javascript :: js stringConstructor type 
Javascript :: javascript check alpha and space only 
Javascript :: one-page web app that requires simple style work. using html, css,javascript and jquery 
Javascript :: what to do when node was already in close in A* algorithm 
Javascript :: curly j 
Javascript :: guardar en una variable la peticion ajax 
Javascript :: route to change a part of component 
Javascript :: elasticsearch reindex and rename field 
Javascript :: vuetify checkbox click firing twice 
Javascript :: set ibm cloud node environment variables 
Javascript :: javascript farbige konsole in node 
Javascript :: sp_oamethod post json 
Javascript :: multiple set in meteor user 
Javascript :: contact form7 404 wp-json feedback 
Javascript :: javascript function with condition in parameter 
Javascript :: how to call javascript method using selectlist on change in vf page 
Javascript :: javascript vérifier si une chaine de carctère commence par une majuscule 
Javascript :: change abclground onload jquery 
Javascript :: minimize and maximize div in html 
Javascript :: scala play json read single field 
Javascript :: setup node and mongodb on centos 7 using npm 
Javascript :: get selected value on componentdidmount reactjs 
Javascript :: jquery validation prevent negative number 
Javascript :: json etudients 
Javascript :: 380/2 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =