javascript繪製心形圖案程式碼例項
本章節分享一段程式碼例項,它實現了繪製心形圖案的效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> div { position: absolute; } .xx-box { left: 50%; top: 50%; margin-left: -250px; margin-top: -250px; width: 500px; height: 500px; background-color: #000; } .xx-box .text { top: 30%; height: 48px; line-height: 48px; color: #f00; text-shadow: 3px 3px 4px #f00; font-size: 36px; font-weight: bold; width: 100%; text-align: center; font-family: Tangerine,Tahoma,Arial,"\65f6\5c1a\4e2d\9ed1\7b80\4f53","\5b8b\4f53"; } .xx-box .item { width: 2px; height: 20px; overflow: hidden; } </style> <script> function createPoint(x, y, c) { var div = document.createElement("div"); div.className = "item"; div.style.left = x + "px"; div.style.top = y + "px"; div.style.backgroundColor = c; document.getElementById("xx-box").appendChild(div); } function heartShape(r, dx, dy, c) {//r:大小;dx:水平偏移;dy:垂直偏移;c:顏色 var m, n, x, y, i; for (i = 0; i <= 200; i += 0.04) { m = i; n=-r*(((Math.sin(i)*Math.sqrt(Math.abs(Math.cos(i))))/(Math.sin(i)+1.4))-2*Math.sin(i)+2); x = n * Math.cos(m) + dx; y = n * Math.sin(m) + dy; createPoint(x, y, c); } } window.onload = function () { heartShape(80, 250, 100, "#f00"); } </script> </head> <body> <div class="xx-box" id="xx-box"> <div class="text">螞蟻部落</div> </div> </body> </html>
相關文章
- css3繪製心形圖案程式碼例項CSSS3
- canvas繪製實心圓形程式碼例項Canvas
- border-radius繪製圓形圖案程式碼例項
- css繪製圓形程式碼例項CSS
- canvas繪製圓形鐘錶程式碼例項Canvas
- Python例項:僅繪製圖例而不繪製實際的圖形Python
- css 心形效果程式碼例項CSS
- javascript輸出菱形圖形程式碼例項JavaScript
- CSS3繪製平行四邊形程式碼例項CSSS3
- css3繪製柳樹葉形狀程式碼例項CSSS3
- canvas繪製扇形程式碼例項Canvas
- canvas繪製星星程式碼例項Canvas
- canvas 繪製雞蛋程式碼例項Canvas
- css3繪製谷歌圖示程式碼例項CSSS3谷歌
- highcharts繪製柱狀圖程式碼例項
- CSS3心形效果程式碼例項CSSS3
- css3繪製QQ企鵝圖示程式碼例項CSSS3
- canvas繪製網格程式碼例項Canvas
- svg繪製半圓程式碼例項SVG
- canvas繪製笑臉程式碼例項Canvas
- canvas繪製圓環效果程式碼例項Canvas
- javascript圓形鐘錶程式碼例項JavaScript
- CSS3繪製太極圖程式碼例項詳解CSSS3
- highcharts繪製折線資料圖程式碼例項
- SVG拖動繪製矩形程式碼例項SVG
- canvas繪製米字旗程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- jQuery繪製網格效果程式碼例項jQuery
- CSS3繪製菱形程式碼例項CSSS3
- canvas繪製拋物線程式碼例項Canvas線程
- canvas繪製機器貓程式碼例項Canvas
- canvas繪製夜空小屋效果程式碼例項Canvas
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas繪製圓角矩形程式碼例項Canvas
- canvas繪製橢圓效果程式碼例項Canvas
- canvas繪製熊貓頭像程式碼例項Canvas
- canvas繪製圓形圖案程式碼示例簡單介紹Canvas
- 如何使用 css 繪製心形CSS