我正在创建一个看起来像windown的html模板,但是调整器有问题

时间:2019-10-09 23:04:28

标签: javascript html css frontend

我正在创建一个类似于web的windown模板,但是我对缩放器有问题,右下角的缩放器工作正常,但是尝试创建右上角的缩放器无效,我也不知道为什么我已经尝试了一切,但是没有用。

这是github https://github.com/alhazacod/windowsxphtmltemplate

JavaScript代码:

dragru.onmousedown = function(event) {
  let shiftLeft = event.clientX - wwindow.getBoundingClientRect().left;
  let shiftTop = event.clientY - wwindow.getBoundingClientRect().top;
  let shiftBottom = - event.clientY + wwindow.getBoundingClientRect().bottom;

  function resize(w, h, pageY){
    wwindow.style.top = pageY - shiftTop + 'px';
    if(w>200){
      wwindow.style.width = w + 'px';
    }
    if(h>200){
      console.log(wwindow.getBoundingClientRect().bottom - event.pageY);
      wwindow.style.height = (wwindow.getBoundingClientRect().bottom - event.pageY) + 'px';

    }
    //wwindow.style.top = pageY - shiftTop + 'px';
  }

  function onMouseMove(event){
    shiftLeft = event.clientX - wwindow.getBoundingClientRect().left;
    shiftBottom = -event.clientY + wwindow.getBoundingClientRect().bottom;
    //if(event.pageY < windowh && event.pageY > 1 && event.pageX < windoww && event.pageX > 1){
      resize(shiftLeft, shiftBottom, event.pageY);
    //}
    /*else{
      document.removeEventListener('mousemove', onMouseMove);
      wwindow.onmouseup = null;
    }*/
  }

  document.addEventListener('mousemove', onMouseMove);

  wwindow.onmouseup = function(){
    document.removeEventListener('mousemove', onMouseMove);
    wwindow.onmouseup = null;
  };
};

0 个答案:

没有答案