SVG (viewBox) & DOM (viewport)
SVG (viewBox) & DOM (viewport)
circle
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-02-10
* @modified 2020-02-11
*
* @description
* @augments
* @example
* @link http://xahlee.info/js/js_scritping_svg_basics.html
* @link https://developer.mozilla.org/zh-CN/docs/Web/API/Element/insertAdjacentHTML
*
*/
// 容器小,circle 大,导致 circle 被剪切
const svgStr = `<svg width="100" height="100"><circle cx="80" cy="80" r="30" fill="grey" stroke="purple"></circle></svg>`;
// ? viewBox 缩放比例
// 容器大,内容小,完全绘制,逆时针,顺时针 ?
const svgMeta = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100" width="100%" height="100%"><circle cx="100" cy="100" r="50" fill="red" stroke="green"></circle></svg>`;
const body = document.querySelector(`body`);
body.insertAdjacentHTML(`beforeend`, svgStr);
body.insertAdjacentHTML(`beforeend`, svgMeta);
const jsCreatSVG = () => {
// create the svg element, namespace
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
// meta
svg.setAttribute("version", "1.1");
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
svg.setAttribute("viewBox", "0 0 100 100");
// set width and height
svg.setAttribute("width", "100");
svg.setAttribute("height", "100");
// create a circle
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("cx", "80");
circle.setAttribute("cy", "80");
circle.setAttribute("r", "30");
circle.setAttribute("fill", "red");
// attach it to the container
svg.appendChild(circle);
// attach container to document
document.querySelector(`body`).appendChild(svg);
};
https://codepen.io/xgqfrms/pen/gOppybr?editors=0010

SVG viewBox & DOM viewport
viewBox
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
https://www.sarasoueidan.com/blog/svg-coordinate-systems/
https://webdesign.tutsplus.com/tutorials/svg-viewport-and-viewbox-for-beginners--cms-30844
http://tutorials.jenkov.com/svg/svg-viewport-view-box.html




xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
SVG (viewBox) & DOM (viewport)的更多相关文章
- SVG 入门——理解viewport,viewbox,preserveAspectRatio
工欲善其事必先利其器,没有真正搞懂SVG里的viewport,viewbox, preserveAspectRatio这三个属性,就很容易遇到坑,最近写项目用到svg这三个属性被我一眼就略过 ,后来发 ...
- 理解SVG中的 viewport,viewBox, preserveAspectRatio
_ 阅读目录 一:理解viewport 二:理解viewBox 三:理解 preserveAspectRatio 回到顶部 一:理解viewport 该属性表示的是SVG可见区域的大小.或者也可以叫画 ...
- SVG viewBox & coordinate system
SVG viewBox & coordinate system https://codepen.io/xgqfrms/pen/abOOrjp <html> <body> ...
- 关于TileBrush中Viewbox,Viewport以及Stretch,AlignmentX/Y的详细研究
我们知道TileBrush是WPF中一个战斗力爆表的虚基类,从它派生出的DrawingBrush,ImageBrush和VisualBrush在WPF图形编程中发挥着重要作用.然而关于TileBrus ...
- 可视化svg深入理解viewport、viewbox、preserveaspectradio
直接运行此例子 深入理解svg的viewport.viewbox.preserveaspectradio实例 <!DOCTYPE html> <html lang="en& ...
- SVG ViewBox
如果svg图形太大或者太小,就可以用ViewBox属性来调整在页面中的显示范围.大小. "像素不能直接换算成英寸.厘米,要在 dpi ( dot per inch 分辨率,概念较多,鼠标 d ...
- 理解SVG的viewport,viewBox,preserveAspectRatio
万丈高楼平地起,基础很重要. viewport 表示SVG可见区域的大小,或者可以想象成舞台大小,画布大小. <svg width="500" height="30 ...
- svg的viewport和viewbox
svg中视区重要的概念 1. viewport 视口,相当于显示器屏幕 2. viewbox 视区,相当于在屏幕上截取一小块,放大到整个屏幕,就是特写的效果 3. preserveAspectR ...
- SVG DOM常用属性和方法介绍
将以Adobe SVG Viewer提供的属性和方法为准,因为不同解析器对JavaScript以及相关的属性和方法支持的程度不同,有些方法和属性是某个解析器所特有的.SVG支持DOM2标准. 12.2 ...
随机推荐
- 关于MongoDB的简单理解(三)--Spring Boot篇
一.前言 Spring Boot集成MongoDB非常简单,主要为加依赖,加配置,编码. 二.说明 环境说明: JDK版本为15(1.8+即可) Spring Boot 2.4.1 三.集成步骤 3. ...
- EasyConnect连接成功后,虚拟ip地位未分配
文章目录 #问题描述: 今天公司做项目,连接上EasyConnect以后,显示连接成功,但是虚拟ip地址未分配,导致无法远程连接数据库,以及svn无法更新项目. #解决办法: 百度网上各种解决办法,没 ...
- apache https 双向证书生成
Https分单向认证和双向认证 单向认证表现形式:网站URL链接为https://xxx.com格式 双向认证表现心事:网站URL链接为https://xxx.com格式,并且需要客户端浏览器安装一个 ...
- Kibana,Logstash 和 Cerebro 的安装运行
公号:码农充电站pro 主页:https://codeshellme.github.io 1,安装 Kibana Kibana 用于数据可视化,我们可以进入到 Kibana 下载页面下载 Kibana ...
- Codeforces Round #345 (Div. 1) C. Table Compression (并查集)
Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorith ...
- hdu4521 小明系列问题——小明序列
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission ...
- HDU - 4221 贪心
题意: 你有n个任务,每一个任务有一个完成所需时间AI,和一个截止时间BI.时间从0开始,如果完成任务的时间(设这个时间为ans)大于BI那么就会收到ans-BI的惩罚,问你完成所有这些任务你会收到的 ...
- Tomacat目录以及服务器配置文件信息
一. 1.Tomacat的启动: 在我的windows10中我下载的是8.5版本的tomacat,我就是通过".sh"文件来打开和关闭tomacat 要打开.sh文件还需要 这个G ...
- 使用eclipse搭建第一个java web应用
一. 首先是eclipse得下载,你要下载Eclipse IDE for Java EE这种类型的,我之前下载的Eclipse IDE for Enterprise Java Developers是官 ...
- windows安装
1.windows系统版本分类a. 个人版windows98.XP.win7,win8,win10b. 企业版/服务器版windows server NT/2000/2003/2008/2012[广泛 ...