readme
1.改變this指向的方式
以下屬于函數的方法
.call();? call(thisScope,arg1,arg2.arg3...)改變this的指向并且調用它
.apply(); apple(thisScope [arg1,arg2.arg3...]);兩個參數:指向,數組.改變this的指向并且調用它
.bind(); bind(thisScope,arg1,arg2.arg3...)改變this的指向,返回的是函數
2.Math對象的方法
Math.random();
Math.ceil();
Math.floor();
Math.round();
Math.sin(); //三角函數
Math.PI;? //圓周率
Math.abs();
Math.max();
Math.min();
Math.pow(); //平方
Math.sqrt(); //開方
3.求數組里面的最大值和最小值
arr = [1,2,3,4,5,6];
Math.max.apply(null,arr);
Math.min.apply(null,arr);
4.獲取非行間樣式
現代瀏覽器支持:getComputedStyle(ele)返回樣式對象 不能修改
如需修改樣式,使用element.style.height = "200px";
IE8以下使用什么來獲取非行間樣式呢?
ele.currentStyle
5.全局函數
setInterval();
setTimeout();
paseInt();
getComputedStyle();
6.document整個文檔對象
document.documentElement 頁面根元素 html
document.body 頁面中body 元素
7.只讀 獲取的是number
(定位父級:祖先元素設置有position:relative/absolute/fixed之一,沒有則為body)
element.offsetParent? 定位父級
element.offsetLeft 相對定位父級的左偏移
element.offsetTop 相對定位父級的上偏移
element.offsetWidth? 寬度 包括 border + padding + width;
element.offsetHeight 高度 包括 border + padding + width;
element.clientWidth? 寬度 包括 padding + width;
element.clientHeight 高度 包括 padding + width;
element.clientTop? 元素上邊框寬度
element.clientLeft? 元素左邊框寬度
8.ele.children 元素ele所有子元素組成的數組[實際上 是類數組對象]
//不能使用真正數組的方法,如push pop unshift shift
2.demo
1.點擊返回頂部
由于 ? document.documentElement.scrollTop = 0;? //chrome 不支持
? ? ? ? ? ?document.body.scrollTop = 0; ? ? ? ? ? ? ? ? ? ? ?//firefox不支持 故封裝一個函數來做兼容,并且使用套路代碼來做緩動.
2.獲取非行間樣式
只能讀取,
由于存在兼容性問題,IE8以下使用currentStyle, 所以下面是兼容性的封裝函數