-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,6 @@ const myProxy = new Proxy(myObj, { | |
}) | ||
|
||
// console.log(myProxy.age) | ||
myProxy.age = '19' | ||
myProxy.age = '19' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
let nums = [1, 2, 4] | ||
|
||
nums = new Proxy(nums, { | ||
get(target, prop) { | ||
if (prop in target) { | ||
return target[prop] | ||
} else { | ||
return 0 | ||
} | ||
} | ||
}) | ||
|
||
console.log(nums[1]) | ||
console.log(nums[22]) | ||
|
||
|
||
|
||
// fo / 16 = win/width | ||
// 640/16 = 40 | ||
// 414/640 * 16 = 10.35px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<style> | ||
.wp { | ||
border: 1px solid red; | ||
width: 300px; | ||
height: 300px; | ||
position: relative; | ||
} | ||
|
||
.box { | ||
height: 50px; | ||
width: 50px; | ||
position: absolute;; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
margin: auto; | ||
background-color: red; | ||
} | ||
|
||
.box.size { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="wp"> | ||
<div class="box">xxx</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
|
||
<style> | ||
.outer { | ||
height: 200px; | ||
background-color: red; | ||
padding: 10px; | ||
} | ||
|
||
.inner { | ||
height: 100px; | ||
background-color: blue; | ||
margin-top: 50px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="outer"> | ||
<div class="inner"></div> | ||
</div> | ||
</body> | ||
|
||
<script> | ||
let inner = document.querySelector('.inner') | ||
let outer = document.querySelector('.outer') | ||
|
||
// 监听outer元素的attribute变化 | ||
new MutationObserver(function() { | ||
console.log('mutate') | ||
}).observe(outer, { | ||
attributes: true | ||
}) | ||
|
||
// click监听事件 | ||
function onClick() { | ||
console.log('click') | ||
|
||
setTimeout(function() { | ||
console.log('timeout') | ||
}, 0) | ||
|
||
outer.setAttribute('data-random', Math.random()) | ||
Promise.resolve().then(function() { | ||
console.log('promise') | ||
}) | ||
} | ||
|
||
inner.addEventListener('click', onClick) | ||
outer.addEventListener('click', onClick) | ||
|
||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<script> | ||
(function (doc, win) { | ||
var rootValue = 100; | ||
var docEl = doc.documentElement, | ||
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', | ||
recalc = function () { | ||
var clientWidth = docEl.clientWidth; | ||
console.log(clientWidth) | ||
if (!clientWidth) return; | ||
docEl.style.fontSize = rootValue * (clientWidth / 640) + 'px'; | ||
}; | ||
if (!doc.addEventListener) return; | ||
win.addEventListener(resizeEvt, recalc, false); | ||
doc.addEventListener('DOMContentLoaded', recalc, false); | ||
})(document, window); | ||
</script> | ||
<style> | ||
.test { | ||
width: 1rem; | ||
height: 16px; | ||
background-color: red; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="test"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
worker.onmessage = function (e) { | ||
console.log(e.data) | ||
} | ||
|
||
|
||
</script> | ||
</body> | ||
|
||
</html> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// 判断类型 | ||
const isType = (type) => (target) => `[object ${type}]` === Object.prototype.toString.call(target) | ||
const isArray = isType('Array') | ||
const isPureObject = isType('Object') | ||
|
||
console.log(isArray([])) |