欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何使用SVG基本操作API-創(chuàng)新互聯(lián)

這篇文章主要介紹如何使用SVG基本操作API,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)公司,是成都地區(qū)的互聯(lián)網(wǎng)解決方案提供商,用心服務(wù)為企業(yè)提供網(wǎng)站建設(shè)、成都app軟件開發(fā)、成都微信小程序、系統(tǒng)定制制作和微信代運(yùn)營服務(wù)。經(jīng)過數(shù)10余年的沉淀與積累,沉淀的是技術(shù)和服務(wù),讓客戶少走彎路,踏實(shí)做事,誠實(shí)做人,用情服務(wù),致力做一個負(fù)責(zé)任、受尊敬的企業(yè)。對客戶負(fù)責(zé),就是對自己負(fù)責(zé),對企業(yè)負(fù)責(zé)。

基礎(chǔ)API

在javascript中,可以使用一些基本的API來對SVG進(jìn)行操作

【NS地址】

因?yàn)镾VG定義在其自身的命令空間下,而不是HTML的命名空間下,可以作為單獨(dú)的XML文件存在。所以需要使用自身的NS地址

有兩個常用的NS地址

var SVG_NS = "http://www.w3.org/2000/svg";
var XLINK_NS = http://www.w3.org/1999/xlink;

【創(chuàng)建圖形】

document.createElementNS(SVG_NS,tagName);

【添加圖形】

element.appendChild(childElement)

【設(shè)置/獲取屬性】

element.setAttribute(name,value);
element.getAttribute(name);

【設(shè)置xlink】

<a>、<textPath>等標(biāo)簽需要設(shè)置xlink屬性

element.setAttributeNS(XLINK_NS,'xlink:href',value);

封裝函數(shù)

將創(chuàng)建標(biāo)簽及添加屬性的操作封閉成一個函數(shù),方便復(fù)用

function createTag(tag,objAttr){
 var oTag = document.createElementNS('http://www.w3.org/2000/svg',tag);
  for(var attr in objAttr){
  if(attr == 'xlink:href'){
   oTag.setAttributeNS("http://www.w3.org/1999/xlink",attr,objAttr[attr]);
  }else{
   oTag.setAttribute(attr,objAttr[attr]);
  }  
  } 
 return oTag;
}

下面通過該函數(shù),創(chuàng)建一個圓形

<script>
function createTag(tag,objAttr){
 var oTag = document.createElementNS('http://www.w3.org/2000/svg',tag);
  for(var attr in objAttr){
  if(attr == 'xlink:href'){
   oTag.setAttributeNS("http://www.w3.org/1999/xlink",attr,objAttr[attr]);
  }else{
   oTag.setAttribute(attr,objAttr[attr]);
  }  
  } 
 return oTag;
} 
var oSvg = createTag('svg',{'version':'1.1','xmls':'http://www.w3.org/2000/svg',height:'70'});
var oCircle = createTag('circle',{'cx':'25','cy':'25','r':20,'fill':'pink'});
oSvg.appendChild(oCircle);
document.body.appendChild(oSvg);
</script>

實(shí)例

下面通過SVG基本操作API,創(chuàng)建一個可交互的SVG實(shí)例

<style>
#box{
 height: 300px;
 width: 300px;
 background: hsl(20,40%,90%);
 background-image:linear-gradient(90deg,#fb3 11px,transparent 0),
 linear-gradient(90deg,#ab4 23px,transparent 0),
 linear-gradient(90deg,#655 41px,transparent 0);
 background-size: 41px 100%,61px 100%,83px 100%; 
} 
</style>
<div id="box"></div>
<script>
var oSvg = createTag('svg',{'version':'1.1','xmls':'http://www.w3.org/2000/svg',height:'100%',width:'100%'});
var oBox = document.getElementById('box');
var W = parseInt(getComputedStyle(oBox).width);
var H = parseInt(getComputedStyle(oBox).height);
var appearance = {
 'dis':H/3,
 'r0':H/8,'r':H/10,
 'x0':W/2,'y0':H/2,
 'fontSize':H/20,
 'bg0':'hsla(0,0%,100%,.6)','bg':'hsla(0,0%,100%,.3)',
 'color0':'hsl(210,13%,30%)','color':'hsl(210,13%,30%)',
 'borderColor0':'rgba(0,0,0,0.3)','bordercolor':'rgba(0,0,0,0.3)',
 'strokWidth0':3,'strokWidth':2,
 'lineColor':'rgba(0,0,0,0.3)','lineWidth':1,'lineDashed':'5,5'
}
var data = {
 text:'前端開發(fā)',
 children:[
  {text:'HTML',url:'http://www.cnblogs.com/xiaohuochai/p/5203223.html'},
  {text:'CSS',url:'http://www.cnblogs.com/xiaohuochai/p/5249139.html'},
  {text:'JS',url:'http://www.cnblogs.com/xiaohuochai/p/5613593.html'},
  {text:'ES6',url:'http://www.cnblogs.com/xiaohuochai/p/7233392.html'},
  {text:'HTTP',url:'http://www.cnblogs.com/xiaohuochai/p/6392010.html'},
  {text:'NodeJS',url:'http://www.cnblogs.com/xiaohuochai/p/6940560.html'},
  {text:'前端工具',url:'http://www.cnblogs.com/xiaohuochai/p/6666415.html'},
 ], 
}
addChildenTags();
addCenterTag();
oBox.appendChild(oSvg);
function createTag(tag,objAttr){
 var oTag = document.createElementNS('http://www.w3.org/2000/svg',tag);
  for(var attr in objAttr){
  if(attr == 'xlink:href'){
   oTag.setAttributeNS("http://www.w3.org/1999/xlink",attr,objAttr[attr]);
  }else{
   oTag.setAttribute(attr,objAttr[attr]);
  }  
  } 
 return oTag;
} 
function addCenterTag(){
 var oG = createTag('g',{'style':'cursor:default'});
 var oCircle = createTag('circle',{'cx':appearance.x0,'cy':appearance.y0,'r':appearance.r0,'fill':appearance.bg0,'stroke':appearance.borderColor0,'stroke-width':appearance.strokWidth0});
 var oText = createTag('text',{'x':appearance.x0,'y':appearance.y0,'font-size':appearance.fontSize,'text-anchor':'middle','dominant-baseline':'middle','stroke-width':appearance.strokWidth0});
 oText.innerHTML = data.text;
 oG.appendChild(oCircle);
 oG.appendChild(oText);
 oSvg.appendChild(oG);
}
function addChildenTags(){
 var children = data.children;
 var length = children.length;
 var deg = (360/length)*(2*Math.PI)/360;
 for(var i = 0; i < children.length;i++){
  var cos = Math.cos(deg*i - 90);
  var sin = Math.sin(deg*i - 90);
  var x = appearance.x0 + appearance.dis*cos;
  var y = appearance.y0 + appearance.dis*sin;
  var oA = createTag('a',{'xlink:href':children[i].url,'target':'_black'}); 
  var oG = createTag('g',{'style':'cursor:pointer'}); 
  oG.index = i;    
  var oLine = createTag('line',{'x1':x-appearance.r*cos,y1:y-appearance.r*sin,x2:appearance.x0+appearance.r0*cos,y2:appearance.y0+appearance.r0*sin,'stroke':appearance.lineColor,'stroke-width':appearance.lineWidth,'stroke-dasharray':appearance.lineDashed,'style':'transition:.5s'});
  var oLineHelper = createTag('line',{'x1':x-appearance.r*cos,y1:y-appearance.r*sin,x2:appearance.x0+appearance.r0*cos,y2:appearance.y0+appearance.r0*sin,'stroke':'transparent','stroke-width':10});  
  var oCircle = createTag('circle',{'cx':x,'cy':y,'r':appearance.r,'fill':appearance.bg,'stroke':appearance.bordercolor,'stroke-width':appearance.strokWidth,'class':'frostedglass'});
  var oText = createTag('text',{'x':x,'y':y,'font-size':appearance.fontSize,'text-anchor':'middle','dominant-baseline':'middle','stroke-width':appearance.strokWidth,fill:appearance.color});
  oText.innerHTML = children[i].text; 
  oG.appendChild(oLine);
  oG.appendChild(oLineHelper);   
  oG.appendChild(oCircle);     
  oG.appendChild(oText);
  oA.appendChild(oG);
  oSvg.appendChild(oA);
  oG.onmouseenter = function(){
   elasticMove(this,appearance.r*1.2);
   var line = this.children[0];
   line.removeAttribute('stroke-dasharray');
   line.setAttribute('stroke-width',appearance.lineWidth*3);
   line.setAttribute('x1',appearance.x0+(appearance.dis - appearance.r0)*Math.cos(deg*this.index - 90));
   line.setAttribute('y1',appearance.y0+(appearance.dis - appearance.r0)*Math.sin(deg*this.index - 90));
  }
  oG.onmouseleave = function(){
   elasticMove(this,appearance.r);
   var line = this.children[0];
   line.setAttribute('stroke-width',appearance.lineWidth);
   line.setAttribute('stroke-dasharray',appearance.lineDashed);
   line.setAttribute('x1',appearance.x0+(appearance.dis - appearance.r)*Math.cos(deg*this.index - 90));
   line.setAttribute('y1',appearance.y0+(appearance.dis - appearance.r)*Math.sin(deg*this.index - 90));   
  }   
 }
}
function elasticMove(obj,str){
 var circle = obj.getElementsByTagName('circle')[0];
 var r0 = circle.getAttribute('r');
 var r = Number(str);
 //聲明步長值
 var step = 0;
 //聲明彈性距離
 var len = r - r0;
 //聲明彈性系數(shù)
 var k = 0.7;
 //聲明損耗系數(shù)
 var z= 0.7;
 //聲明當(dāng)前值
 var cur = r0;
 clearInterval(circle.timer);
 circle.timer = setInterval(function(){
  //獲取當(dāng)前值cur
  cur = circle.getAttribute('r');
  //更新彈性距離
  len = r - cur;
  //彈力影響
  step += len*k;
  //阻力影響
  step = step*z;
  //賦值
  circle.setAttribute('r',Number(cur) + step);
  //當(dāng)元素的步長值接近于0,并且彈性距離接近于0時,停止定時器
  if(Math.round(step) == 0 && Math.round(len) == 0){
   circle.setAttribute('r',r);
   clearInterval(circle.timer); 
  } 
 },30);
}
</script>

以上是“如何使用SVG基本操作API”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)頁標(biāo)題:如何使用SVG基本操作API-創(chuàng)新互聯(lián)
分享路徑:http://chinadenli.net/article36/ehssg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化網(wǎng)站收錄軟件開發(fā)、網(wǎng)站設(shè)計(jì)網(wǎng)站設(shè)計(jì)公司、動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
日本人妻的诱惑在线观看| 久久人妻人人澡人人妻| 国产大屁股喷水在线观看视频| 国产熟女一区二区三区四区| 人妻熟女欲求不满一区二区| 亚洲内射人妻一区二区| 欧美一区二区三区十区| 亚洲精品偷拍一区二区三区| 丝袜av一区二区三区四区五区| 日本加勒比系列在线播放| 国产欧美另类激情久久久| 国产精品视频一级香蕉| 久久国产精品亚州精品毛片| 少妇人妻一级片一区二区三区| 六月丁香六月综合缴情| 国产日本欧美韩国在线| 91福利免费一区二区三区| 国产一区二区不卡在线播放 | 污污黄黄的成年亚洲毛片| 欧美精品一区久久精品| 亚洲精品国产美女久久久99| 九九蜜桃视频香蕉视频| 欧美有码黄片免费在线视频| 国产精品不卡免费视频| 日韩不卡一区二区在线| 国产精品刮毛视频不卡| 91免费精品国自产拍偷拍| 日韩成人高清免费在线| 日本精品免费在线观看| 成人欧美一区二区三区视频| 微拍一区二区三区福利| 国产三级视频不卡在线观看| 国产级别精品一区二区视频 | 99秋霞在线观看视频| 亚洲精品中文字幕欧美| 久久精品亚洲精品一区| 人妻亚洲一区二区三区| 精品人妻一区二区三区免费| 成人午夜激情在线免费观看| 亚洲精品国产第一区二区多人| 99久久免费中文字幕|