当前位置:网站首页>js,e.pageX、pageY模态框拖动
js,e.pageX、pageY模态框拖动
2022-07-26 10:24:00 【唐策】
手写模态框拖动功能
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.tk-modal{
position: absolute;
width: 300px;
}
.tk-modal-header{
border: 1px solid #ccc;
width: 200px;
}
.tk-modal-close{
width: 50px;
}
</style>
</head>
<body>
<div class="tk-modal tk-ask-modal">
<div class="tk-modal-header">
<div class="tk-modal-close fright">关闭</div>
</div>
<div class="tk-modal-maintk-modal-main"></div>
</div>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
// 模态窗
// 模态窗关闭
tkModalOpen($(".tk-ask-modal"));
$(document).on("click",".tk-modal-close,.tk-modal-footer-cancel",function(){
tkModalClose($(this).parents(".tk-modal"));
});
var _move=false;//移动标记
var _x,_y;//鼠标离控件左上角的相对位置
$(document).on("click",".tk-modal-header",function(){
//alert("click");//点击(松开后触发)
}).on("mousedown",".tk-modal-header",function(e){
_move=true;
_x=e.pageX-parseInt($(this).parent(".tk-modal").css("left"));
_y=e.pageY-parseInt($(this).parent(".tk-modal").css("top"));
// console.log(_x+_x)
});
$(document).mousemove(function(e){
if(_move){
var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
var y=e.pageY-_y;
$(".tk-modal").css({top:y,left:x});//控件新位置
// console.log(x)
}
}).mouseup(function(){
_move=false;
});
// 打开模态框
function tkModalOpen(obj){
$(".tk-overlay").show();
$("body").height($(window).height()).css({
"overflow-y": "hidden"
});
$left=(document.body.clientWidth-obj.width())/2;
$top=document.body.clientHeight>obj.height()?(document.body.clientHeight-obj.height())/2:0;
obj.css({"left":$left,"top":$top});
obj.show();
};
// 关闭模态框
function tkModalClose(obj){
obj.hide();
$(".tk-overlay").hide();
$("body").css({
"overflow-y": "visible"
});
};
})
</script>
</body>
</html>
边栏推荐
- 新建福厦铁路全线贯通 这将给福建沿海带来什么?
- PTA class a 1001
- 【Halcon视觉】阈值分割
- Data communication foundation telnet remote management equipment
- SQL Server 2008 R2 installation problems
- Nacos custom service change subscription
- 详细解析js中的混合方式构造对象(构造加属性,原型加方法)
- Study notes at the end of summer vacation
- Structure of [Halcon vision] operator
- 函数模板参数(函数参数在哪)
猜你喜欢

【Halcon视觉】图像滤波

【Halcon视觉】编程逻辑
![Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da](/img/21/5dceab9815b503f0b62d26a430d7eb.png)
Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da

INSTALL_FAILED_SHARED_USER_INCOMPATIBLE错误解决方式

新建福厦铁路全线贯通 这将给福建沿海带来什么?

【Halcon视觉】算子的结构

Review of database -- 1. Overview

Learning about opencv (4)

议程速递 | 7月27日分论坛议程一览

equals与==的区别
随机推荐
【杂谈】Error loading psycopg2 module :No module named psycopg2
Okaleido生态核心权益OKA,尽在聚变Mining模式
数通基础-Telnet远程管理设备
Dynamically determine file types through links
The difference between equals and = =
What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?
利用原生js实现自定义滚动条(可点击到达,拖动到达)
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
【Halcon视觉】阈值分割
软件打不开了
函数模板与同名的非模板函数不可以重载(重载的定义)
Opencv image processing
What is wrong about the description of function templates (how to solve link format errors)
How to write a million reading article
【Halcon视觉】图像滤波
Learning about tensorflow (I)
点赞,《新程序员》电子书限时免费领啦!
Okaleido ecological core equity Oka, all in fusion mining mode
Basics of data communication - basic knowledge of network
Prevent XSS attacks