角度計測

    @@ -7,20 +7,22 @@ */ var x1,y1,x2,y2,dx,dy; -var div = $(document.createElement('div')) - .css({ - 'width': '100%', - 'height': '65535px', + +$('body').append( + $('<div>').css({ 'position': 'absolute', - 'z-index': '9999', - }) - .toggle( - function(e){x1 = e.pageX; y1 = e.pageY;}, - function(e){x2 = e.pageX; y2 = e.pageY;prompt('角度',calculate());$(this).remove()} + 'z-index': '999999', + 'top':'0', + 'left':'0', + 'right': '0', + 'height': '65535px' + }).toggle( + function(e){ x1 = e.pageX; y1 = e.pageY; }, + function(e){ x2 = e.pageX; y2 = e.pageY; prompt('角度', calculate()); $(this).remove(); } ) -; -$('body').prepend(div); +); + -function calculate(){ - return Math.atan2(y2-y1, x2-x1)*180/Math.PI +function calculate() { + return Math.atan2(y2-y1, x2-x1)*180/Math.PI; }
  • /*
     * @title 角度計測
     * @description 2点をクリックしてちゃんと計算する。角度とか。(右方向水平が0度)
     * @include http://*
     * @license MIT License
     * @require jQuery
     */
    
    var x1,y1,x2,y2,dx,dy;
    
    $('body').append(
      $('<div>').css({
        'position': 'absolute',
        'z-index': '999999',
        'top':'0',
        'left':'0',
        'right': '0',
        'height': '65535px'
      }).toggle(
        function(e){ x1 = e.pageX; y1 = e.pageY; },
        function(e){ x2 = e.pageX; y2 = e.pageY; prompt('角度', calculate()); $(this).remove(); }
      )
    );
    
    
    function calculate() {
      return Math.atan2(y2-y1, x2-x1)*180/Math.PI;
    }
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2012/03/21 17:34:37 - 2012-03-21
  2. 2012/03/21 17:24:45 - 2012-03-21
  3. 2012/03/21 17:20:13 - 2012-03-21
  4. 2012/03/21 17:11:47 - 2012-03-21