1. 程式人生 > 實用技巧 >linu安裝nginx、php7.3、mysql5.7以及相關環境配置

linu安裝nginx、php7.3、mysql5.7以及相關環境配置

技術標籤:js基礎案例js

小栗子

移動端拖拽

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style> div { width: 100px; height: 100px; background: #c33; position: absolute; left: 0; top: 0; } </style> <body> <div></div> <script> // 1.觸控元素 touchstart: 獲取手指初始座標,同時獲得盒子原來的位置 // 2.移動手指 touchmove: 計算手指的滑動距離,並且移動盒子 // 3.離開手指 touchend
let div = document.querySelector('div'); let startX = 0 //獲取手指初始座標 let startY = 0 let x = 0 //獲取盒子原來的位置 let y = 0; div.addEventListener('touchstart',function(e){ // 獲取手指初始座標 startX = e.targetTouches[0].pageX; startY = e.targetTouches[0].pageY; x = this.offsetLeft;
y = this.offsetTop }) div.addEventListener('touchmove',function(e){ // 計算手指的移動距離,手指移動之後的座標減去手指初始的座標 let moveX = e.targetTouches[0].pageX - startX; let moveY = e.targetTouches[0].pageY - startY; // 移動我們的盒子 盒子原來的位置 + 手指移動的距離 this.style.left = x + moveX + 'px' this.style.top = y + moveY + 'px' e.preventDefault(); //阻止螢幕滾動的預設行為 }) </script> </body> </html>

pc端拖拽

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  .dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    width: 312px;
    height: 280px;
    border: 1px solid #ebebeb;
    box-shadow: 0px 0px 20px #ddd;
    background-color: #ddd;
  }
  #title {
    width: 100%;
    height: 40px;
    background-color: aqua;
  }
  span {
    width: 100px;
    height: 100px;
    background-color: #c33;
    position: absolute;
    left: 0;
  }
</style>
<body>
  <div class="dialog">
    <h2 id="title">一些內容</h2>
    <input type="text">
    <hr/>
  <script>

let span = document.querySelector('span')
let button = document.querySelector('button')
console.log(span.offsetLeft,'obj.offsetLeft');

button.addEventListener('click',function(){
  animate(span,500)
})

let title = document.getElementById('title');
    let dialog = document.getElementsByClassName('dialog');
    title.addEventListener('mousedown', function(e){
      console.log(dialog);
      let x = e.pageX - dialog[0].offsetLeft;
      let y = e.pageY - dialog[0].offsetTop;
      document.addEventListener('mousemove',move)
      function move(e){
        dialog[0].style.left = e.pageX - x +'px';
        dialog[0].style.top = e.pageY - x +'px';
    }
    
    document.addEventListener('mouseup',function(e){
     document.removeEventListener('mousemove',move)
    })
    })

  </script>
</body>
</html>