加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.html 2.17 KB
一键复制 编辑 原始数据 按行查看 历史
hans 提交于 2020-10-15 20:48 . init
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mini图标浏览器</title>
<style>
#selectBox {
width: 20px;
height: 20px;
border: 1px solid blue;
position: absolute;
}
body {
TEXT-ALIGN: center;
}
#center {
margin-left: auto;
margin-right: auto;
}
</style>
<script type="text/javascript">
function getOffset(evt) {
var target = evt.target;
if (target.offsetLeft == undefined) {
target = target.parentNode;
}
var pageCoord = getPageCoord(target);
var eventCoord = {
x : window.pageXOffset + evt.clientX,
y : window.pageYOffset + evt.clientY
};
var offset = {
offsetX : eventCoord.x - pageCoord.x,
offsetY : eventCoord.y - pageCoord.y
};
return offset;
}
function getPageCoord(element) {
var coord = {
x : 0,
y : 0
};
while (element) {
coord.x += element.offsetLeft;
coord.y += element.offsetTop;
element = element.offsetParent;
}
return coord;
}
function setIconIndex(event, target) {
var offset = event;
if (!offset.offsetX) {
offset = getOffset(event);
}
var offsetX = floorNumber(offset.offsetX, 20);
var offsetY = floorNumber(offset.offsetY, 20);
var iconPath = " url(>skin>common/icons.gif) -" + offsetX + "px -"
+ offsetY + "px";
document.getElementById(target).value = iconPath;
if (target == 'selectIcon') {
var subX = event.clientX - offset.offsetX + offsetX;
var subY = event.clientY - offset.offsetY + offsetY;
setDivLocation("selectBox", subX, subY);
}
}
function floorNumber(num, divisor) {
return Math.floor(num / divisor) * divisor;
}
function setDivLocation(id, x, y) {
var css = document.getElementById(id).style;
css.left = x + "px";
css.top = y + "px";
}
</script>
</head>
<body>
<div id="center">
当前选择图标 <br /> <input type="text" id="selectIcon" size="50" /> <br />
鼠标指向图标 <br /> <input type="text" id="pointIcon" size="50" /> <br />
<img src="icons.gif" onmousemove="setIconIndex(event, 'pointIcon')"
onClick="setIconIndex(event, 'selectIcon')" />
</div>
<div id="selectBox"></div>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化