2015-04-17 85 views
1

我想滾動SVG文件使用IMG/1.png圖像的HTML ID標籤如何讓svg對象點擊鏈接?

我的HTML塊

<object width="1024" height="597" data="svg/index/1.svg" type="image/svg+xml" id="pdf1" style="width:1024px; height:597px; background-color:white; -moz-transform:scale(1); z-index: 0;"> 
</object> 

我的SVG文件1.svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <defs> 
      <style type="text/css"><![CDATA[ 
      .g1_1{ 
        fill: #8FEFCA; 
        fill-opacity: 0.71000695; 
      } 
      .g2_1{ 
        fill: #8EDBED; 
        fill-opacity: 0.5399929; 
      } 
      ]]></style> 
    </defs> 
    <path d="M1024,597L0,597L0,320l1024,0l0,277Z" class="g1_1" /> 
    <path d="M455,597l569,0L1024,0l-9,0Z" class="g2_1" /> 
    <a xlink:href="#p2"> 
      <image x="690" y="290" width="25" height="24" xlink:href="img/1.png" /> 
    </a> 
</svg> 

我試着使用jquery裏面的svg文件,但我沒有在html文件中聲明的jquery滾動函數不叫

<div id = "p2"> scroll here </div> 

測試網址:http://cabitsystems.com/svgtest/tt.html

+4

現代瀏覽器可以在' '標籤。你有沒有試過,而不是使用''? –

+0

'SVG's是自己的對象,'jquery'不能訪問它們的內部或者計算它們中的'offset'。你可以嘗試使用純JavaScript,但我懷疑這是行不通的,因爲SVG中的元素與viewbox,svg的大小等相比是偏移的。SVG不應該用於此目的。 – somethinghere

+0

這裏是測試網址:http://cabitsystems.com/svgtest/tt.html雅我用對象 –

回答

0

我解決這個法子....我從SVG文件中提取圖像,然後使用位置把它在SVG

HTML塊

<a href="#p2" onclick="alert('hiii')"> 
    <img src="svg/index/img/1.png" id="p1x" x="690" y="290" z="300" width="25" height="24"> 
</a> 

和小css

a { 
    display: inline-block; 
    /* padding: 27px; */ 
    font-size: 17px; 
    font-family: 'Open Sans', sans-serif; 
    text-decoration: none; 
    color: white; 
    left: 685px; 
    top: 200px; 
    position: absolute; 
+0

儘管這樣做有效,但它首先擊敗了SVG的所有目的,不是嗎?您以像素爲單位定義了所有像素,因此這不會像SVG所打算做的那樣縮放。 – somethinghere

+0

雅我同意,將不得不尋找更好的解決方案,但現在是緊急:) –