SVG.图形在网页中的位置

1、<svg/>直接写在 html中,得到 svg中图形(图形A)的位置,将浮动的<div/>移动到 图形A的上方

2、测试代码:(chrome for windows 版本 56.0.2924.87 中 效果OK)

1<!--内联 XHTML--> 2<!-- 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4--> 5<!--内联 HTML5--> 6<!DOCTYPE html> 7 8<html> 9<head> 10 <meta charset="UTF-8"> 11 12 13 <script type="text/javascript" > 14 <!-- 15 16 window.onload = function() 17 { 18 var svgRect = document.getElementById("svgRect"); 19 var rt = svgRect.getBoundingClientRect(); 20 console.log(rt+""); 21 console.log("rt.top : "+rt.top); 22 console.log("rt.left : "+rt.left); 23 24 console.log(""); 25 26 var divPiao = document.getElementById("divPiao"); 27 //divPiao.setAttribute("top", rt.top+"px"); 28 //divPiao.setAttribute("left", rt.left+"px"); 29 console.log("divPiao.style.top : "+divPiao.style.top); 30 console.log("divPiao.style.left : "+divPiao.style.left); 31 divPiao.style.top = rt.top +"px"; 32 divPiao.style.left = rt.left +"px"; 33 console.log("divPiao.style.top : "+divPiao.style.top); 34 console.log("divPiao.style.left : "+divPiao.style.left); 35 }; 36 37 --> 38 </script> 39 40</head> 41 42<body> 43 44 <div> 45 AAA<br/> 46 bbb<br/> 47 CCC<br/> 48 </div> 49 50 <svg width="1000" height="800" viewBox="0 0 1000 800" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" > 51 <rect id="svgRect" x="100" y="100" width="100" height="200" style="stroke:black; stroke-width:2px; fill:none;"/> 52 </svg> 53 54 <div id="divPiao" style="position:absolute; top:10px; left:10px; width:100px; height:150px; background-color:red;"> 55 </div> 56 57</body> 58</html>

3、

4、

5、

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

AndroidStudio封装SDK的那些事

<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael