где SVG-код связан с html, body, header, javascript, css - PullRequest
0 голосов
/ 24 августа 2010

не могли бы вы дать мне такую ​​структуру:

<html><body><svg></svg><javascript>..............</html> ??

У меня много проблем с добавлением CSS и JavaScript в файл SVG, который выглядит следующим образом:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   version="1.0"
   width="958.69"
   height="592.78998"
   id="svg2275"
   sodipodi:version="0.32"
   inkscape:version="0.46"
   sodipodi:docname="Map of USA with state names.svg"
   sodipodi:docbase="C:\temp\webdesign"
   inkscape:output_extension="org.inkscape.output.svg.inkscape">


    <script type="text/ecmascript">
    <![CDATA[

      function showRectArea(state) {
        var x = new Object();
        x["HI"] = "you clicked hawaii";
        x["CT"] = "you clicked CT";
        alert(x[state]);
      }

      var tooltip=function(){
      var id = 'tt';
 var top = 3;
 var left = 3;
 var maxw = 300;
 var speed = 10;
 var timer = 20;
 var endalpha = 95;
 var alpha = 0;
 var tt,t,c,b,h;
 var ie = document.all ? true : false;
 return{
  show:function(v,w){
   if(tt == null){
    tt = document.createElement('div');
    tt.setAttribute('id',id);
    t = document.createElement('div');
    t.setAttribute('id',id + 'top');
    c = document.createElement('div');
    c.setAttribute('id',id + 'cont');
    b = document.createElement('div');
    b.setAttribute('id',id + 'bot');
    tt.appendChild(t);
    tt.appendChild(c);
    tt.appendChild(b);
    document.body.appendChild(tt);
    tt.style.opacity = 0;
    tt.style.filter = 'alpha(opacity=0)';
    document.onmousemove = this.pos;
   }
   tt.style.display = 'block';
   c.innerHTML = v;
   tt.style.width = w ? w + 'px' : 'auto';
   if(!w && ie){
    t.style.display = 'none';
    b.style.display = 'none';
    tt.style.width = tt.offsetWidth;
    t.style.display = 'block';
    b.style.display = 'block';
   }
  if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  h = parseInt(tt.offsetHeight) + top;
  clearInterval(tt.timer);
  tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  },
  pos:function(e){
   var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
   var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
   tt.style.top = (u - h) + 'px';
   tt.style.left = (l + left) + 'px';
  },
  fade:function(d){
   var a = alpha;
   if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    var i = speed;
   if(endalpha - a < speed && d == 1){
    i = endalpha - a;
   }else if(alpha < speed && d == -1){
     i = a;
   }
   alpha = a + (i * d);
   tt.style.opacity = alpha * .01;
etc
etc
etc
etc

Ответы [ 2 ]

1 голос
/ 24 августа 2010

В прошлый раз я использовал SVG для генератора графиков во встроенной системе, и этот граф представлялся как отдельный объект SVG. Кроме того, я использовал XHTML 1.0.

Content-Type: image/svg+xml
// Some other HTTP headers here...

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
    "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    width="100px" height="100px" viewBox="-0.5 -0.5 99.5 99.5">
<!-- svg stuff goes here -->
</svg>

(Нет, я не жестко закодировал размеры 100x100; я просто заполнил их для этого примера.)

1 голос
/ 24 августа 2010

Смотрите это для некоторого базового фона в svg: http://www.w3schools.com/svg/svg_inhtml.asp относительно тегов embed, object и iframe на странице HTML.

Что касается окончательного результата того, что вы пытаетесь ...это остается быть изолированным, представленным и таким образом решенным!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...