css常見知識點
1.內(nèi)核區(qū)分
希望某一個瀏覽器能一統(tǒng)江湖
-ms-transform:rotate(7deg); //-ms代表ie內(nèi)核識別碼
-moz-transform:rotate(7deg); //-moz代表火狐內(nèi)核識別碼
-webkit-transform:rotate(7deg); //-webkit代表谷歌內(nèi)核識別碼
-o-transform:rotate(7deg); //-o代表歐朋【opera】內(nèi)核識別碼
transform:rotate(7deg); //統(tǒng)一標識語句。。。最好這句話也寫下去,符合w3c標準
2.屏幕的高度
js獲取 /******************** * 取窗口滾動條滾動高度 ******************/ function getScrollTop() { var scrollTop=0; if(document.documentElement&&document.documentElement.scrollTop) { scrollTop=document.documentElement.scrollTop; } else if(document.body) { scrollTop=document.body.scrollTop; } return scrollTop; } /******************** * 取窗口可視范圍的高度 *******************/ function getClientHeight() { var clientHeight=0; if(document.body.clientHeight&&document.documentElement.clientHeight) { var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight; } else { var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight; } return clientHeight; } /******************** * 取文檔內(nèi)容實際高度 *******************/ function getScrollHeight(){ return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight); } //////////////////////////////////////////////////// 在IE中: document.body.clientWidth ==> BODY對象寬度 document.body.clientHeight ==> BODY對象高度 document.documentElement.clientWidth ==> 可見區(qū)域?qū)挾?document.documentElement.clientHeight ==> 可見區(qū)域高度 在FireFox中: document.body.clientWidth ==> BODY對象寬度 document.body.clientHeight ==> BODY對象高度 document.documentElement.clientWidth ==> 可見區(qū)域?qū)挾?document.documentElement.clientHeight ==> 可見區(qū)域高度 在Opera中: document.body.clientWidth ==> 可見區(qū)域?qū)挾?document.body.clientHeight ==> 可見區(qū)域高度 document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬) document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)
3.jquery獲取屏幕的尺寸
//獲取瀏覽器顯示區(qū)域(可視區(qū)域)的高度 : $(window).height(); //獲取瀏覽器顯示區(qū)域(可視區(qū)域)的寬度 : $(window).width(); //獲取頁面的文檔高度 $(document).height(); //獲取頁面的文檔寬度 : $(document).width(); //瀏覽器當前窗口文檔body的高度: $(document.body).height(); //瀏覽器當前窗口文檔body的寬度: $(document.body).width(); //獲取滾動條到頂部的垂直高度 (即網(wǎng)頁被卷上去的高度) $(document).scrollTop(); //獲取滾動條到左邊的垂直寬度 : $(document).scrollLeft(); //獲取或設置元素的寬度: $(obj).width(); //獲取或設置元素的高度: $(obj).height(); //某個元素的上邊界到body最頂部的距離:obj.offset().top;(在元素的包含元素不含滾動條的情況下) //某個元素的左邊界到body最左邊的距離:obj.offset().left;(在元素的包含元素不含滾動條的情況下) //返回當前元素的上邊界到它的包含元素的上邊界的偏移量:obj.offset().top(在元素的包含元素含滾動條的情況下) //返回當前元素的左邊界到它的包含元素的左邊界的偏移量:obj.offset().left(在元素的包含元素含滾動條的
4.jquery獲取位置
//獲取頁面某一元素的絕對X,Y坐標,可以用offset()方法: var top = $('#ID').offset().top; var left = $('#ID').offset().left; //獲取相對(父元素)位置: var top = $('#ID').position().top; var left = $('#ID').position().left; //position()方法相對父元素是指擁有position為relative或absolute屬性的父元素。 //讓Div隨滾動條移動: <div id="oLayer" style="position: absolute; left: 0; top:80px; z-index: 2; background: a9c9ef; margin-left:6px;width: 140px; height: 70px"> </div> //jquery代碼: $(window).scroll(function() { var init_pos = $('#oLayer').offset().top; $('#oLayer').css("top", $(window).scrollTop()+80) });
5.常見的寬度和高度獲取
網(wǎng)頁可見區(qū)域?qū)挘?document.body.clientWidth 網(wǎng)頁可見區(qū)域高: document.body.clientHeight 網(wǎng)頁可見區(qū)域?qū)挘?document.body.offsetWidth (包括邊線的寬) 網(wǎng)頁可見區(qū)域高: document.body.offsetHeight (包括邊線的高) 網(wǎng)頁正文全文寬: document.body.scrollWidth 網(wǎng)頁正文全文高: document.body.scrollHeight 網(wǎng)頁被卷去的高: document.body.scrollTop 網(wǎng)頁被卷去的左: document.body.scrollLeft 網(wǎng)頁正文部分上: window.screenTop 網(wǎng)頁正文部分左: window.screenLeft 屏幕分辨率的高: window.screen.height 屏幕分辨率的寬: window.screen.width 屏幕可用工作區(qū)高度: window.screen.availHeight 屏幕可用工作區(qū)寬度: window.screen.availWidth <script language="javascript"> function screenInfo(){ var s = ""; s += "\r\n網(wǎng)頁可見區(qū)域?qū)挘?+ document.body.clientWidth; s += "\r\n網(wǎng)頁可見區(qū)域高:"+ document.body.clientHeight; s += "\r\n網(wǎng)頁可見區(qū)域?qū)挘?+ document.body.offsetWidth +" (包括邊線的寬)"; s += "\r\n網(wǎng)頁可見區(qū)域高:"+ document.body.offsetHeight +" (包括邊線的寬)"; s += "\r\n網(wǎng)頁正文全文寬:"+ document.body.scrollWidth; s += "\r\n網(wǎng)頁正文全文高:"+ document.body.scrollHeight; s += "\r\n網(wǎng)頁被卷去的高:"+ document.body.scrollTop; s += "\r\n網(wǎng)頁被卷去的左:"+ document.body.scrollLeft; s += "\r\n網(wǎng)頁正文部分上:"+ window.screenTop; s += "\r\n網(wǎng)頁正文部分左:"+ window.screenLeft; s += "\r\n屏幕分辨率的高:"+ window.screen.height; s += "\r\n屏幕分辨率的寬:"+ window.screen.width; s += "\r\n屏幕可用工作區(qū)高度:"+ window.screen.availHeight; s += "\r\n屏幕可用工作區(qū)寬度:"+ window.screen.availWidth; alert(s); } </script>
6.CSS動畫
animation 屬性是一個簡寫屬性,用于設置六個動畫屬性:
語法:animation: name duration timing-function delay iteration-count direction;
下面的表格列出了 @keyframes 規(guī)則和所有動畫屬性:
| 屬性 | 描述 | CSS |
|---|---|---|
| @keyframes | 規(guī)定動畫。 | 3 |
| animation | 所有動畫屬性的簡寫屬性,除了 animation-play-state 屬性。 | 3 |
| animation-name | 規(guī)定 @keyframes 動畫的名稱。 | 3 |
| animation-duration | 規(guī)定動畫完成一個周期所花費的秒或毫秒。默認是 0。 | 3 |
| animation-timing-function | 規(guī)定動畫的速度曲線。默認是 "ease"。 | 3 |
| animation-delay | 規(guī)定動畫何時開始。默認是 0。 | 3 |
| animation-iteration-count | 規(guī)定動畫被播放的次數(shù)。默認是 1。 | 3 |
| animation-direction | 規(guī)定動畫是否在下一周期逆向地播放。默認是 "normal"。 | 3 |
| animation-play-state | 規(guī)定動畫是否正在運行或暫停。默認是 "running"。 | 3 |
| animation-fill-mode | 規(guī)定對象動畫時間之外的狀態(tài)。 | 3 |
語法解釋:
1.動畫名稱animation 屬性是一個簡寫屬性,用于設置六個動畫屬性:
animation-name: none | IDENT[,none | IDENT]*;
animation-name:是用來定義一個動畫的名稱,其主要有兩個值:IDENT是由Keyframes創(chuàng)建的動畫名,換句話說此處的IDENT要和Keyframes中的IDENT一致,如果不一致,將不能實現(xiàn)任何動畫效果;none為默認值,當值為none時,將沒有任何動畫效果。另外我們這個屬性跟前面所講的transition一樣,我們可以同時附幾個animation給一個元素,我們只需要用逗號“,”隔開。
2.動畫播放持續(xù)的時間
animation-duration: <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">time>[,<<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">time>]*
animation-duration是用來指定元素播放動畫所持續(xù)的時間長,取值:為數(shù)值,單位為s (秒.)其默認值為“0”。
3.動畫播放方式
animation-timing-function:ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(<<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>, <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>, <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>, <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>) [, ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(<<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>, <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>, <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>, <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>)]*
animation-timing-function:是指元素根據(jù)時間的推進來改變屬性值的變換速率,說得簡單點就是動畫的播放方式.具有以下六種變換方式:ease;ease-in;ease-in-out;linear;cubic-bezier。雖然這個屬性么有用過,這里要了解一下這個屬性的枚舉值。animation-timing-function 使用名為三次貝塞爾(Cubic Bezier)函數(shù)的數(shù)學函數(shù),來生成速度曲線。您能夠在該函數(shù)中使用自己的值,也可以預定義的值:
| 值 | 描述 | 測試 |
|---|---|---|
| linear | 動畫從頭到尾的速度是相同的。 | 測試 |
| ease | 默認。動畫以低速開始,然后加快,在結(jié)束前變慢。 | 測試 |
| ease-in | 動畫以低速開始。 | 測試 |
| ease-out | 動畫以低速結(jié)束。 | 測試 |
| ease-in-out | 動畫以低速開始和結(jié)束。 | 測試 |
| cubic-bezier(n,n,n,n) | 在 cubic-bezier 函數(shù)中自己的值。可能的值是從 0 到 1 的數(shù)值。 |
4.動畫開始時間
animation-delay: <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">time>[,<<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">time>]*
animation-delay:是用來指定元素動畫開始時間。取值為為數(shù)值,單位為s(秒),其默認值也是0。
5.動畫循環(huán)次數(shù)
animation-iteration-count:infinite | <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number> [, infinite | <<SPAN style="COLOR: rgb(38,139,210); MARGIN-LEFT: 60px" class="title">number>]*
animation-iteration-count是用來指定元素播放動畫的循環(huán)次數(shù),其可以取值為數(shù)字,其默認值為“1”;infinite為無限次數(shù)循環(huán)。
6.動畫播放方向
animation-direction: normal | alternate [, normal | alternate]*
animation-direction是用來指定元素動畫播放的方向,其只有兩個值,默認值為normal,如果設置為normal時,動畫的每次循環(huán)都是向前播放;另一個值是alternate,他的作用是,動畫播放在第偶數(shù)次向前播放,第奇數(shù)次向反方向播放。
7.動畫播放狀態(tài)
animation-play-state:running | paused [, running | paused]*
animation-play-state主要是用來控制元素動畫的播放狀態(tài)。其主要有兩個值,running和paused其中running為默認值。他們的作用就類似于我們的音樂播放器一樣,可以通過paused將正在播放的動畫停下了,也可以通過running將暫停的動畫重新播放,我們這里的重新播放不一定是從元素動畫的開始播放,而是從你暫停的那個位置開始播放。另外如果暫時了動畫的播放,元素的樣式將回到最原始設置狀態(tài)。這個屬性目前很少內(nèi)核支持,所以只是稍微提一下。
8.動畫最終狀態(tài)
animation-fill-mode : none | forwards | backwards | both;
animation-fill-mode 屬性規(guī)定動畫在播放之前或之后,其動畫效果是否可見。這個在設置從底部向上滑動,左側(cè)導航的頁面的時候很有用,如果不設置這個屬性會回到開始狀態(tài)。
| 值 | 描述 |
|---|---|
| none | 不改變默認行為。 |
| forwards | 當動畫完成后,保持最后一個屬性值(在最后一個關鍵幀中定義)。 |
| backwards | 在 animation-delay 所指定的一段時間內(nèi),在動畫顯示之前,應用開始屬性值(在第一個關鍵幀中定義)。 |
| both | 向前和向后填充模式都被應用。 |
作者:Tyler Ning
出處:http://www.rzrgm.cn/tylerdonet/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,如有問題,請微信聯(lián)系冬天里的一把火
浙公網(wǎng)安備 33010602011771號