javascript繪製漂亮的心型線效果完整執行個體,javascript繪製執行個體

來源:互聯網
上載者:User

javascript繪製漂亮的心型線效果完整執行個體,javascript繪製執行個體

本文執行個體講述了javascript繪製漂亮的心型線效果實現方法。分享給大家供大家參考,具體如下:

運行效果如下:

具體代碼如下:

<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>JS心型線</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></head><body><div class="xx-box" id="xx-box">  <div class="text">I Love You</div></div><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);  }}heartShape(80,250,100,"#f00");</script></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.