4 Star 1 Fork 1

刘娇951128/宏信环科-油库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
测试.html 3.13 KB
一键复制 编辑 原始数据 按行查看 历史
liu-jiao943076981 提交于 2021-07-07 08:55 . 初始化
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
width: 1580px;
height: 910px;
overflow: hidden;
position: relative;
border: 1px solid #000;
}
div img {
position: absolute;
height: 100%;
width: auto;
cursor: move;
}
</style>
</head>
<body>
<div id="div" onmousewheel="return bbimg(this)"><img id="img" border="0" src="img/map_img.jpg" style="height: 100%;width: 100%;"/></div>
<script language="javascript">
var params = {
zoomVal:1,
left: 0,
top: 0,
currentX: 0,
currentY: 0,
flag: false
};
//图片缩放
function bbimg(o){
var o=o.getElementsByTagName("img")[0];
params.zoomVal+=event.wheelDelta/1200;
if (params.zoomVal >= 1) {
o.style.transform="scale("+params.zoomVal+")";
} else {
params.zoomVal=1;
o.style.transform="scale("+params.zoomVal+")";
return false;
}
}
//获取相关CSS属性
var getCss = function(o,key){
return o.currentStyle? o.currentStyle[key] : document.defaultView.getComputedStyle(o,false)[key];
};
//拖拽的实现
var startDrag = function(bar, target, callback){
if(getCss(target, "left") !== "auto"){
params.left = getCss(target, "left");
}
if(getCss(target, "top") !== "auto"){
params.top = getCss(target, "top");
}
//o是移动对象
bar.onmousedown = function(event){
params.flag = true;
if(!event){
event = window.event;
//防止IE文字选中
bar.onselectstart = function(){
return false;
}
}
var e = event;
params.currentX = e.clientX;
params.currentY = e.clientY;
};
document.onmouseup = function(){
params.flag = false;
if(getCss(target, "left") !== "auto"){
params.left = getCss(target, "left");
}
if(getCss(target, "top") !== "auto"){
params.top = getCss(target, "top");
}
};
document.onmousemove = function(event){
var e = event ? event: window.event;
if(params.flag){
var nowX = e.clientX, nowY = e.clientY;
var disX = nowX - params.currentX, disY = nowY - params.currentY;
target.style.left = parseInt(params.left) + disX+ "px";
target.style.top = parseInt(params.top) + disY+ "px";
if (typeof callback == "function") {
callback((parseInt(params.left) || 0) + disX, (parseInt(params.top) || 0) + disY);
}
if (event.preventDefault) {
event.preventDefault();
}
return false;
}
}
};
startDrag(document.getElementById("img"),document.getElementById("img"))
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liu-jiao-951128/hongxin-huanke-oil-depot.git
[email protected]:liu-jiao-951128/hongxin-huanke-oil-depot.git
liu-jiao-951128
hongxin-huanke-oil-depot
宏信环科-油库
master

搜索帮助