最近比較閒,在家作點訓練javascript
http://ife.baidu.com/course/detail/id/18?t=1527144851578#learncss
https://www.cnblogs.com/jesse131/p/5441199.htmlhtml
做業提交截止時間:09-01前端
此課程按照簡單到難的順序一共有八個任務,由淺入深的帶你們瞭解 Web 動效落地方法 。完成這八道題,你會掌握以下技能:java
git|github
的能力。
1:行內元素水平居中 text-align:center;css3
2:button樣式git
button{ padding: 0; border: none; font: inherit; color: inherit; background-color: transparent; /* show a hand cursor on hover; some argue that we should keep the default arrow cursor for buttons */ cursor: pointer; } .btn{ background-color: #fff; border: 1px solid #ccc; border-radius:4px; padding: 0.5em 1em; margin-top: 5px; }
3:transition4個屬性github
transition: width 0.5s ease-out 1s;
4:Cannot set property 'width' of undefined?瀏覽器
這個問題不是CSS的問題,而是一個純javascript的問題。 你的css寫得沒錯,問題出在Javascript當中的 getElementsByClassName("aa"),這個方法獲得的是一個由class="aa"的全部元素組成的集合,而不是單個元素; 集合是沒有display屬性的,集合中的元素纔有display屬性。當你試圖作 集合.style.display的時候,天然會報錯。 因此你這個問題的解決方案應該是:遍歷集合中全部的元素,而後給每一個元素都加上display="none"的屬性。示例代碼以下: window.onload = function (){ divset = document.getElementsByClassName("aa"); for (var i = 0; i<divset.length;i++) { divset[i].style.display="none"; }; }
5:JS修改CSS樣式post
var obj = document.getElementById("btnB"); ① obj.style.backgroundColor= "black"; ② obj.setAttribute("class", "style2"); https://www.cnblogs.com/susufufu/p/5749922.html(全解)
6:原生JS事件寫法
https://www.cnblogs.com/iyangyuan/p/4190773.html
7:僞類after和before的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style> button{ padding: 0; border: none; font: inherit; color: inherit; background-color: transparent; /* show a hand cursor on hover; some argue that we should keep the default arrow cursor for buttons */ cursor: pointer; } .btn{ background-color: #fff; border: 1px solid #ccc; border-radius:4px; padding: 0.5em 1em; margin-top: 5px; } div{ text-align:center; } .hr{ width:0; display: inline-block; height: 0px; border-top:1px solid blue; transition: width 0.5s ease-out; } p{ transition: color 0.5s ease-out; } .box{ border:1px solid #ebebeb; padding: 20px 10px; margin:20px; background-color: #f7f6f6; display: inline-block; } .box1{ transform: skew(30deg); } .box2{ transform: scale(0.5,1); } .box3{ transform: rotate(45deg); } .box4{ transform: translate(10px,20px); } .box5{ transform: translate(20px,40px) rotate(45deg) scale(2,1) skew(30deg); } </style> <body> <div> <p>前端學院</p> <div class="hr"></div> <br> <button class="btn" onclick="change()">按鈕</button> <br> <div class="box">box0</div> <div class="box box1">box1</div> <div class="box box2">box2</div> <div class="box box3">box3</div> <div class="box box4">box4</div> <div class="box box5">box5</div> </div> </body> <script> function change(){ var hr = document.getElementsByClassName('hr'); var p = document.getElementsByTagName('p'); console.log(hr[0].style.width); if(hr[0].style.width){ hr[0].style.width=null; p[0].style.color="black"; }else{ hr[0].style.width="100px"; p[0].style.color="blue"; } } </script> </html>