SVG click event Designs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!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>

  

posted @   ®Geovin Du Dream Park™  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2016-01-08 How to get the query string by javascript?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示