1 / 13

JavaScript and CSS

JavaScript and CSS. http://www.w3schools.com/jsref/dom_obj_style.asp. style. 使用 style 物件存取 css 屬性 : document.getElementById(" id ").style. property =" value "; 所有屬性值都是 字串 型態。 Style object property categories: Background Border and Margin Layout List Positioning Table Text. Examples.

Download Presentation

JavaScript and CSS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript and CSS http://www.w3schools.com/jsref/dom_obj_style.asp

  2. style • 使用style物件存取css屬性: document.getElementById("id").style.property="value"; • 所有屬性值都是字串型態。 • Style object property categories: • Background • Border and Margin • Layout • List • Positioning • Table • Text

  3. Examples div1= document.getElementById("content"); div1.style.width = "800px"; div1.style.padding = "10px 20px 0px"; div.style.backgroundColor="#ccf"; div.style.fontSize=“2.5em”; div1.style.fontSize=(parseFloat(div.style.fontSize)*1.2)+"em"; div1.style.width = (parseInt(div1.style.width)+50)+"px"; div1.style.width +=50; // 錯誤!

  4. Examples • img1.style.opacity=1.0; • img2.style.opacity=0.0; • … • function imgShow() { • o1 = parseFloat(img1.style.opacity); • o2 = parseFloat(img2.style.opacity); • o1 -= 0.02; • o2 += 0.02; • img1.style.opacity=o1; • img2.style.opacity = o2; • if (o1>0) • window.setTimeout("imgShow()", 200); • } http://ycchen.im.ncnu.edu.tw/www2011/lab/opacityJS.html

  5. CSS屬性名稱對應

  6. Background

  7. Border and Margin borderborderTopborderRightborderBottomborderLeft borderColorborderTopColorborderRightColorborderBottomColorborderLeftColor borderStyleborderTopStyleborderRightStyleborderBottomStyleborderLeftStyle borderWidthborderTopWidthborderRightWidthborderBottomWidthborderLeftWidth marginmarginTopmarginRightmarginBottommarginLeft paddingpaddingToppaddingRightpaddingBottompaddingLeft

  8. Layout

  9. var cardPool=document.getElementById(“cardPool”); document.getElementById("btnStart").onclick=start; document.getElementById("btnStop").onclick=stop; cardPool.style.display="none"; … function start() { cardPool.style.display=“block"; … } function stop() { cardPool.style.display="none"; } <div id="cardPool"> <script type="text/javascript"> for (var i=0;i<5;i++) document.write("<img id=\""+i+"\" src=\"pcards/b1fv.png\" />"); </script> </div> http://ycchen.im.ncnu.edu.tw/www2011/lab/pcard.html

  10. List

  11. Positioning

  12. Table

  13. Text

More Related