일상 문제 공유
동적 가져오기div 높이
window.onresize(){...}
$(window).resize(function(){...}
가로 화면 금지
$(function(){
// :
function hengshuping(){
// if(window.orientation==180||window.orientation==0){
// alert(" !")
// }
if(window.orientation==90||window.orientation==-90){
alert(" , ")
}
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false);
})
질문
calc () = calc (사칙 연산)
width: calc(100% - 10px)
width:-moz-calc(100% - 10px);
width:-webkit-calc(100% - 10px);
--
firefox 4.0+ calc() , -moz-calc() ;
chrome 19 dev , -webkit-calc() ;
IE9 ,calc();
Opera ~~
-->
브라우저의 시각적 높이 가져오기
-1. IE9+、chrome、firefox、Opera、Safari
window.innerHeight
window.innerWidth
var w = document.documentElement.clientWidth || document.body.clientWidth;
var h = document.documentElement.clientHeight || document.body.clientHeight;
클릭하여 관통
방법1: 이벤트.stopPropagation()
이 메서드는 이벤트가 다른 Document 노드로 디스패치되지 않도록 전파를 중지합니다.사건이 전파되는 어느 단계에서든 그것을 호출할 수 있다.이 방법은 같은 문서 노드의 다른 이벤트 핸들이 호출되는 것을 막을 수는 없지만, 이벤트를 다른 노드로 나누는 것을 막을 수 있습니다.
"mask">
"img">
"btn-close">
var mask = document.getElementsByClassName('mask')[0];
var img = document.getElementsByClassName('img')[0];
var btn = document.getElementsByClassName('btn-close')[0];
console.log(mask);
mask.onclick = function(){
console.log(1111)
event.stopPropagation()
};
img.onclick = function(){
console.log(222)
event.stopPropagation()
};
btn.onclick = function(){
console.log(3333)
event.stopPropagation()
};
현재 환경이 OS인지 안드로이드인지 판단
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
} else if (/(Android)/i.test(navigator.userAgent)) {
} else {
this.isIos = true
}
메모리 누설
몇 가지 흔히 볼 수 있는 메모리 유출
1. 글로벌 변수
a = "aaa"
function foo(){
this.a = 'aaa'
}
// ,this
foo();
2. 타이머나 리셋 함수를 제때에 정리하지 않음
function b() {
var a = setInterval(function() {
console.log("Hello");
clearInterval(a);
b();
}, 50);
}
function init()
{
window.ref = window.setInterval(function() { draw(); }, 50);
}
function draw(){
console.log('Hello');
clearInterval(window.ref);
init();
}
init();
function time(f, time) {
return function walk() {
clearTimeout(aeta);
var aeta =setTimeout(function () {
f();
walk();
}, time);
};
}
time(updateFormat, 1000)();
3.dom에서 벗어난 인용(모든 인용 삭제)
var elements = {
button: document.getElementById('button'),
}
function doStuff() {
button.click();
}
function removeButton() {
// body
document.body.removeChild(document.getElementById('button'));
// , #button
// elements 。button , GC 。
}
가방을 닫다
내용이 너무 많아서 자세한 내용은 이것을 보셔도 됩니다.csdn.net/haogexiaole…
js의 사용 팁 www.haorooms.com/post/js_shi…
전재 대상:https://juejin.im/post/5b8de30c518825430e572d1a
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.