Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div>
  <div class="svg-floater">
<svg width="400px" height="350px" id="svg">
  <circle id="cursor-tracker" cx="0", cy="0" r="10"/>
   <polygon id="pointer" points="180,350 200,300 220,350" style="fill:red;stroke-width:1" />
</svg>
  </div>
  <div class="labels">
    <div id="y-label"><strong>Adjacent</strong>(dy): <span id="dy-txt">350</span></div>
    <div id="x-label"><strong>Opposite</strong>(dx): <span id="dx-txt">200</span></div>
    <div id="y-label"><strong>Angle</strong>(degrees): <span id="angle-txt">0</span></div>
    <div id="y-label"><strong>Angle</strong>(radians): <span id="ac-txt">0</span></div>
    
  </div>
</div>
              
            
!

CSS

              
                html {
  width: 100%;
  position: relative;
  font-family: sans-serif;
}

.svg-floater, .labels {
  width: 400px;
  margin: 0px auto;
  touch-action: none;
}

.labels div {
  display: inline;
  width: 50%;
  float: right;
}

line {
  stroke-dasharray: 1 5;
  stroke-width: 3;
  stroke-linecap: round;
  stroke: black;
}
              
            
!

JS

              
                // Collect all our items that we need
var circle = document.getElementById('cursor-tracker');
var pointer = document.getElementById('pointer');
var svg = document.getElementById('svg');
var dxTxt = document.getElementById('dx-txt');
var dyTxt = document.getElementById('dy-txt');
var acTxt = document.getElementById('ac-txt');
var angleTxt = document.getElementById('angle-txt');

// Define some variables
var arrowLoc = {
  x: 200,
  y: 350
}

svg.addEventListener('mousemove', function(event) {
  //console.log(event.clientX, event.clientY);
  updateComponents(event.clientX, event.clientY);
});

svg.addEventListener('touchmove', function(event) {
  //console.log(event);
  updateComponents(event.changedTouches[0].clientX, event.changedTouches[0].clientY);
})


function updateComponents(x, y) {
  // First, we need to do a coordinate change because the x and y origin of the SVG is offset from that of the page.
  x -= 5 + svg.getBoundingClientRect().x;
  y -= 5 + svg.getBoundingClientRect().y;
  
  // Now we move the circle as well as the lines so they demonstrate the triangle.
  circle.setAttribute("cx", x);
  circle.setAttribute("cy", y);
  
  var dx = x - arrowLoc.x;
  var dy = y - arrowLoc.y;
  var angle = Math.atan2(dy,dx);
  
  
  // Now round the values and display them
  dxTxt.innerHTML = Math.round(dx);
  dyTxt.innerHTML = Math.round(dy);
  acTxt.innerHTML = angle;
  angleTxt.innerHTML = Math.round(angle * 180 / Math.PI);
}
              
            
!
999px

Console