1. 程式人生 > 其它 >擴充套件SpringMVC配置

擴充套件SpringMVC配置

//div

  <canvas id="theCanvas" width="800" height="400"></canvas>
//mounted

mounted(){

  cavs() {
      let theCanvas = document.querySelector("#theCanvas");

      if (!theCanvas || !theCanvas.getContext) {
        return false;
      } else {
        let context = theCanvas.getContext("2d"
); const windowToCanvas = (canvas, x, y) => { //獲取canvas元素距離視窗的一些屬性,MDN上有解釋 let rect = canvas.getBoundingClientRect(); //x和y引數分別傳入的是滑鼠距離視窗的座標,然後減去canvas距離視窗左邊和頂部的距離。 return { x: x - rect.left * (canvas.width / rect.width), y: y
- rect.top * (canvas.height / rect.height), }; }; theCanvas.onmousedown = function (e) { //獲得滑鼠按下的點相對canvas的座標。 let ele = windowToCanvas(theCanvas, e.clientX, e.clientY); //es6的解構賦值 let { x, y } = ele; //繪製起點。 context.moveTo(x, y); }; theCanvas.onmousedown
= function (e) { //獲得滑鼠按下的點相對canvas的座標。 let ele = windowToCanvas(theCanvas, e.clientX, e.clientY); //es6的解構賦值 let { x, y } = ele; //繪製起點。 context.moveTo(x, y); //滑鼠移動事件 theCanvas.onmousemove = (e) => { //移動時獲取新的座標位置,用lineTo記錄當前的座標,然後stroke繪製上一個點到當前點的路徑 let ele = windowToCanvas(theCanvas, e.clientX, e.clientY); let { x, y } = ele; context.lineTo(x, y); context.stroke(); };
//這種方法是直線
// theCanvas.onmouseup = (e) => {// let ele = windowToCanvas(theCanvas, e.clientX, e.clientY); // let { x, y } = ele; // context.lineTo(x, y); // context.stroke(); // }; }; } }, }

效果:

參考事件:

滑鼠事件型別
事件型別 說明
click 單擊滑鼠左鍵時發生,如果右鍵也按下則不會發生。當用戶的焦點在按鈕上並按了 Enter 鍵時,同樣會觸發這個事件
dblclick 雙擊滑鼠左鍵時發生,如果右鍵也按下則不會發生
mousedown 滑鼠按鈕被按下時發生
mouseout 滑鼠指標位於某個元素上且將要移出元素的邊界時發生
mouseover 滑鼠指標移出某個元素到另一個元素上時發生
mouseup 滑鼠按鍵被鬆開時發生
mousemove 滑鼠在某個元素上時持續發生
mouseleave 當滑鼠指標移出元素時觸發
mouseenter 當滑鼠指標移動到元素上時觸發。
contextmenu 在使用者點選滑鼠右鍵開啟上下文選單時觸發