Skip to content

Commit

Permalink
fix:修复火狐与ie11不能正常执行
Browse files Browse the repository at this point in the history
  • Loading branch information
biterabbit committed Sep 2, 2019
1 parent 9bec83c commit 22ace56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="uft-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="nowX-UA-Compatible" content="ie=edge">
<title>可拖拽改变大小的弹窗</title>
Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
window.onload = function () {

//获取改变大小边缘的父级盒子
const changebox = document.querySelector('.changebox'),
var changebox = document.querySelector('.changebox'),
//获取弹窗
bt = document.querySelector('.bt'),
title = document.querySelector('.title'),
popup = document.querySelector('.popup'),
popupBg = document.querySelector('.popup-bg'),
big = document.querySelector('.big'),
close = document.querySelector('.close');
let isDrag = false,//拖动标志
var isDrag = false,//拖动标志
isResize = false,//改变大小标志
isBig = false;
let leftbox, topbox, beforeX, beforeY, beforeHeight, beforeWidth, nowX, nowY, maxLeft, maxTop,
var leftbox, topbox, beforeX, beforeY, beforeHeight, beforeWidth, nowX, nowY, maxLeft, maxTop,
switchDirection, width, height, top, left, orginal;

//弹窗按钮
bt.addEventListener('click', () => {
bt.addEventListener('click', function () {
popupBg.style.display = 'block'
popup.style.left = (document.documentElement.clientWidth - popup.offsetWidth) / 2 + 'px'
})
//最大化按钮
big.addEventListener('click', () => {
big.addEventListener('click', function () {
if (isBig) {
//恢复最大化前的位置和大小
popup.style.top = orginal.top
Expand All @@ -46,15 +46,15 @@ window.onload = function () {

})
//关闭按钮
close.addEventListener('click', () => {
close.addEventListener('click', function () {
popupBg.style.display = 'none'
})
//弹窗背景盒子初始化
popupBg.style.height = document.documentElement.clientHeight + 'px'
popupBg.style.width = document.documentElement.clientWidth + 'px'

//鼠标按下选中弹窗标题变为可拖动,同时获取鼠标据弹窗左和上的距离及可拖动的最大距离
title.addEventListener('mousedown', (e) => {
title.addEventListener('mousedown', function (e) {
e = e || window.event
maxTop = document.documentElement.clientHeight - popup.offsetHeight
maxLeft = document.documentElement.clientWidth - popup.offsetWidth
Expand All @@ -64,13 +64,13 @@ window.onload = function () {
})

//鼠标松开,变为不可拖动和拖拽改变大小
document.addEventListener('mouseup', () => {
document.addEventListener('mouseup', function () {
isDrag = false
isResize = false
})

//鼠标移动时改变大小或拖动弹窗
document.addEventListener('mousemove', (e) => {
document.addEventListener('mousemove', function (e) {
e = e || window.event
//阻止事件默认行为和事件冒泡
pauseEvent(e)
Expand Down Expand Up @@ -150,7 +150,7 @@ window.onload = function () {
})

// 使用事件代理为边框上的添加监听
changebox.addEventListener('mousedown', (e) => {
changebox.addEventListener('mousedown', function (e) {
e = e || window.event
//获取改变大小前的鼠标位置和弹窗宽高
if (e.target) {
Expand Down

0 comments on commit 22ace56

Please sign in to comment.