首页 > 其他分享 >SVG click event Designs

SVG click event Designs

时间:2023-01-08 20:13:43浏览次数:36  
标签:Designs container SVG 100% event width position click

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SVG click event Designs</title>
	<meta name="Description" content="geovindu"/>
<meta name="Keywords" content="geovindu"/>
<meta name="author" content="geovindu"/>
	
  <script src="ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript"></script>
	 <script src="bootstrap/4.6.2/js/bootstrap.min.js" type="text/javascript"></script>
  <link rel="stylesheet" href="bootstrap/4.6.2/css/bootstrap.min.css">
	  <script  src="js/jquery-3.6.0.js"></script>
	 <script  type="text/javascript" src="assets/js/DuSize.js"></script>
  <link rel="stylesheet" href="css/main.css">
			<style>
	
  *{
    margin:0 auto;
	padding: 0
  }
			
.container{
    width: 100%;
    position: relative;
    overflow: hidden;	  
	  
  }	
  .container > svg{
    width: 33.333%;
	height: 100%;/*56.5%*/
    float: left;
	 position: relative; 
    /*position: absolute;*/
    border: 0px solid #ccc;
    margin-bottom: 0px;
  }
  .container > svg:after {
    content: '\20';
    padding-top:99.99%;
    display: block;
  }		
	
	  .container > object{
    width: 33.333%;
	height: 100%;/*56.5%*/
    float: left;
	 position: relative; 
    /*position: absolute;*/
    border: 0px solid #ccc;
    margin-bottom: 0px;
  }
  .container > object:after {
    content: '\20';
    padding-top:99.99%;
    display: block;
  }	
  img{
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
  }



/* enabled svg click event */
svg {
  pointer-events: all;
	cursor:pointer;
}

      

</style>
</head>

<body>	
<div class="container">		
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="15" y="15" width="40" height="40" fill="red">
<set attributeName="fill" to="blue" begin="click"/>
</rect>
</svg>	
	
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe">
<![CDATA[	
document.addEventListener('click', changeColor);	
function changeColor(evt)
{
var rect = evt.target;
rect.setAttributeNS(null, "fill", "blue")
}
]]></script>
<rect x="5" y="5" width="40" height="40"
fill="red"
οnclick= "changeColor(evt)"/> u
</svg>	
<svg onclick="makeShape(evt)" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<script type="text/ecmascript">
<![CDATA[
//document.getElementById("Layer_1").dispatchEvent(new Event('click'));	
	
var svgns = "http://www.w3.org/2000/svg";
function makeShape(evt) {
svgDoc = evt.target.ownerDocument;
var rect = svgDoc.createElementNS(svgns, "rect");
rect.setAttributeNS(null, "x", "5");
rect.setAttributeNS(null, "y", "5");
rect.setAttributeNS(null, "width", "40");
rect.setAttributeNS(null, "height", "40");
rect.setAttributeNS(null, "fill", "red");
var set = svgDoc.createElementNS(svgns, "set");
set.setAttributeNS(null, "attributeName", "fill");
set.setAttributeNS(null, "to", "blue");
set.setAttributeNS(null, "begin", "click");
rect.appendChild(set);
svgDoc.rootElement.appendChild(rect);
}
]]></script>
<rect x="5" y="5" width="40" height="40"
fill="red" οnclick="makeShape(evt)"></rect>
</svg>
	</div>
	
<div class="container">
	<svg  xmlns='http://www.w3.org/2000/svg' version='1.1' height='600' width='820' οnlοad="makeShape(evt)">
<script type="text/ecmascript"><![CDATA[
		//https://css-tricks.com/links-inline-svg-staying-target-events/
	//document.getElementById("targetElm").dispatchEvent(new Event('click'));	
		
var svgns = "http://www.w3.org/2000/svg";
function makeShape(evt) {
if (window.svgDocument == null )
svgDoc = evt.target.ownerDocument;
var rect = svgDoc.createElementNS(svgns, "rect");
rect.setAttributeNS(null, "x", 15);
rect.setAttributeNS(null, "y", 15);
rect.setAttributeNS(null, "width", 40);
rect.setAttributeNS(null, "height", 40);
rect.setAttributeNS(null, "fill", "red");
rect.addEventListener("click", changeColor, false); 
svgDoc.documentElement.appendChild(rect);
}
		
function changeColor(evt)
{
var target = evt.target;
target.setAttributeNS(null, "fill", "blue");
}
		
]]></script>
		<rect id="targetElm" x="5" y="5" width="40" height="40"
fill="red"  onclick="makeShape(evt)"></rect>
</svg>
	
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='600' width='820'>

  <script type="text/ecmascript"><![CDATA[
		  //https://www.smashingmagazine.com/2018/05/svg-interaction-pointer-events-property/
      function changerect(evt) {
        var svgobj=evt.target;
        svgobj.style.opacity= 0.3;
        svgobj.setAttribute ('x', 300);
      }
    ]]>
  </script>

  <rect onclick='changerect(evt)' style='fill:blue;opacity:1' x='10' y='30' width='100'height='100' />
</svg>
	</div>
</body>
</html>

  

标签:Designs,container,SVG,100%,event,width,position,click
From: https://www.cnblogs.com/geovindu/p/17035228.html

相关文章

  • 大数据 - ClickHouse
    ​​https://clickhouse.com/​​概念ClickHouse是俄罗斯的Yandex于2016年开源的列式存储数据库(DBMS),使用C++语言编写,主要用于在线分析处理查询(OLAP),能够使用SQL查询......
  • ClickHouse入门
    ClickHouse入门版本21.7.3.14ClickHouse是列式存储数据库(DBMS),主要用于在线分析处理查询(OLAP)。ClickHouse对函数是大小写敏感的,不管是什么操作,还是区分大小写好点官......
  • clickhouse-local
    clickhouse-local可以使你能够对本地文件执行快速处理,而无需部署和配置ClickHouseServer。可以理解成是ClickHouse服务的单机版微内核,是一个轻量级的应用程序clickhouse-......
  • clickhouse安装
    检查当前的CPU是否支持SSE4.2如果不支持SSE指令集,则不能直接使用先前下载的预编译安装包,需要通过源码编译特定的版本进行安装。grep-qsse4_2/proc/cpuinfo&&echo"......
  • Clickhouse优缺点及性能情况
    优点:1,为了高效的使用CPU,数据不仅仅按列存储,同时还按向量进行处理;2,数据压缩空间大,减少IO;处理单查询高吞吐量每台服务器每秒最多数十亿行;3,索引非B树结构,不需要满足最左原......
  • svg 贝塞尔曲线画法
     svg贝塞尔曲线画法https://cubic-bezier.com/#.48,.46,.38,.8 <animateattributeName="x"dur="5s"values="0;80;160"keyTimes="0;.8;1"calcMode="spline......
  • 大数据 - ClickHouse
    https://clickhouse.com/概念ClickHouse是俄罗斯的Yandex于2016年开源的列式存储数据库(DBMS),使用C++语言编写,主要用于在线分析处理查询(OLAP),能够使用SQL查询实时......
  • Spark+ClickHouse实战企业级数据仓库,进军大厂必备(最新升级版21章)
    ​​点击下载:Spark+ClickHouse实战企业级数据仓库,进军大厂必备(最新升级版21章)​​ 提取码:vg2t《Spark+ClickHouse实战企业级数据仓库,进军大厂必备》,2023年1月最新升级版2......
  • [clickhouse]同步MySQL
    前言clickhouse的查询速度非常快,而且兼容大部分MySQL的sql语法,因此一般将clickhouse作为MySQL的读库。本文提供两种clickhouse同步MySQL的方式clickhouse版本:21.2.4.6......
  • svg动起来
    <svgwidth="320"height="320"xmlns="http://www.w3.org/2000/svg"><g><textfont-family="microsoftyahei"font-size="120"y="160"x="160">马</text>......