欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js解決movebox移動問題

 更新時間:2016年03月29日 14:42:02   作者:月光為鄰  
這篇文章主要為大家詳細介紹了js解決movebox移動問題,取消圖片默認拖動事件,感興趣的小伙伴們可以參考一下

本文為大家分享了js解決movebox移動問題,并且取消圖片默認拖動事件的相關操作,供大家參考,具體內容如下

html:

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
  <link href="../Content/StyleSheet5.css" rel="stylesheet" /> 
  <script src="../Scripts/JavaScript5.js"></script> 
  <title></title> 
  <meta charset="utf-8" /> 
</head> 
<body> 
  <div id="center"> 
    <div id="black"></div> 
    <div id="movebox"> 
      <img id="moveimg" src="../Images/b.jpg"/> 
    </div> 
    <img id="bigimg" src="../Images/b.jpg" /> 
  </div> 
</body> 
</html> 

js:

var movebox; 
window.onload = function () { 
  movebox = document.getElementById("movebox"); 
  movebox.addEventListener("mousedown", function (e) { 
    if (e.button > 0) { 
      fun2(); 
      return false; 
    } 
    e.preventDefault && e.preventDefault(); //明哥:去掉圖片拖動響應 狠重要 
    gen.x = e.clientX; 
    gen.y = e.clientY; 
    gen._x = movebox.offsetLeft; 
    gen._y = movebox.offsetTop; 
    gen.dx = gen.x - gen._x; 
    gen.dy = gen.y - gen._y; 
    document.addEventListener("mousemove",fun1,false); 
    document.addEventListener("mouseup", fun2, false); 
  }, false); 
}; 
var fun1 = function (e) { 
  gen.L = e.clientX - gen.dx; 
  gen.T = e.clientY - gen.dy; 
  var timefun = function () { 
    window.getSelection().removeAllRanges(); 
    if (gen.L < 100) 
      gen.L = 100; 
    else if (gen.L > 200) 
      gen.L = 200; 
    if (gen.T < 125) 
      gen.T = 125; 
    else if (gen.T > 175) 
      gen.T = 175; 
    setLT(movebox, gen.L, gen.T); 
  }; 
  setTimeout(timefun, 2); 
}; 
var fun2 = function () { 
  document.removeEventListener("mousemove", fun1, false); 
  document.removeEventListener("mouseuo", fun2, false); 
}; 
var gen = { 
  x: null, 
  y: null, 
  _x: null, 
  _y: null, 
  dx: null, 
  dy: null, 
  L: null, 
  T:null, 
}; 
var setLT = function (dom, L, T) { 
  dom.style.left = L + "px"; 
  dom.style.top = T + "px"; 
}; 

css:

body { 
  position:absolute; 
  margin:0; 
  padding:0; 
} 
#center{ 
  position:absolute; 
  top:200px; 
  left:300px; 
  width:400px; 
  height:400px; 
  background-color:#808080; 
} 
#black{ 
  position:absolute; 
  width:400px; 
  height:400px; 
  z-index:80; 
  background-color:#000; 
  opacity:0.6; 
} 
#bigimg{ 
  z-index:50; 
  position:absolute; 
  left:100px; 
  top:125px; 
} 
#movebox{ 
  z-index:100; 
  position:absolute; 
  width:100px; 
  height:100px; 
  left:150px; 
  top:150px; 
  overflow:hidden; 
  cursor:move; 
  background-color:#ff6a00; 
} 
#moveimg{ 
  position:absolute; 
  left:-50px; 
  top:-25px; 
} 

以上就是本文的全部內容,希望對大家的學習有所幫助。

相關文章

  • JSON生成Form表單的方法示例

    JSON生成Form表單的方法示例

    JSON表單是一個基于React的抽象組件,它可以把JSON數(shù)據格式描述的表單轉換成項目中的表單,這篇文章主要介紹了JSON生成Form表單的方法示例,感興趣的小伙伴們可以參考一下
    2018-11-11
  • js實現(xiàn)ctrl+v粘貼上傳圖片(兼容chrome、firefox、ie11)

    js實現(xiàn)ctrl+v粘貼上傳圖片(兼容chrome、firefox、ie11)

    這篇文章主要為大家詳細介紹了js實現(xiàn)ctrl+v粘貼上傳圖片,兼容chrome,firefox,ie11,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • webpack打包多頁面的方法

    webpack打包多頁面的方法

    這篇文章主要介紹了webpack打包多頁面的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • D3.js進階系列之CSV表格文件的讀取詳解

    D3.js進階系列之CSV表格文件的讀取詳解

    D3.js支持從外部讀取數(shù)據進行圖形交互(Loading External Resources),支持的格式有CSV、txt、Html、tsv、xml文本文件和JSON XML數(shù)據結構,下面這篇文章主要給大家介紹了D3.js中CSV表格文件讀取的相關資料,需要的朋友可以參考下。
    2017-06-06
  • JavaScript defineProperty如何實現(xiàn)屬性劫持

    JavaScript defineProperty如何實現(xiàn)屬性劫持

    雙向數(shù)據綁定的核心方法,主要是做數(shù)據劫持操作(監(jiān)控數(shù)據變化),下面這篇文章主要給大家介紹了關于JavaScript defineProperty如何實現(xiàn)屬性劫持的相關資料,需要的朋友可以參考下
    2021-07-07
  • JS實現(xiàn)的透明度漸變動畫效果示例

    JS實現(xiàn)的透明度漸變動畫效果示例

    這篇文章主要介紹了JS實現(xiàn)的透明度漸變動畫效果,涉及javascript響應鼠標事件針對頁面元素屬性動態(tài)操作相關實現(xiàn)技巧,需要的朋友可以參考下
    2018-04-04
  • 原生js封裝自定義滾動條

    原生js封裝自定義滾動條

    本文主要介紹了原生js封裝自定義滾動條的相關知識。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • js獲取下拉列表框<option>中的value和text的值示例代碼

    js獲取下拉列表框<option>中的value和text的值示例代碼

    本篇文章主要是對js獲取下拉列表框<option>中的value和text的值示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • form表單數(shù)據封裝成json格式并提交給服務器的實現(xiàn)方法

    form表單數(shù)據封裝成json格式并提交給服務器的實現(xiàn)方法

    下面小編就為大家分享一篇form表單數(shù)據封裝成json格式并提交給服務器的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • Bootstrap實現(xiàn)圓角、圓形頭像和響應式圖片

    Bootstrap實現(xiàn)圓角、圓形頭像和響應式圖片

    這篇文章主要介紹了Bootstrap實現(xiàn)圓角、圓形頭像和響應式圖片的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12

最新評論