Raphaeljs support in IE8

不问归期 提交于 2019-12-06 14:17:32
Simeon

As you may or may not know, Raphaël produces VML for IE6-8, and SVG for all other browsers. However, VML and SVG works quite differently. This is very inadequately documented in Raphaël.

The issue you are experiencing is due to the fact that you are adding an href attribute to the elements, i.e. ptm.attr({'href':'ptm_sp.php?ptm_sp=h3R2ci'});, which works fine for SVG, since SVG elements can have events in the same manner as DOM elements.

For VML though, you will have to attach the Raphaël specific click function to the object, and produce document.location.href = 'http://URL'; inside of that. The Raphaël events are listed here, but please ignore the paragaph about using your favourite library, as this is incorrect for VML.

Example code that should help you solve your problem:

ptm.click(function(){
    location.href = 'ptm_sp.php?ptm_sp=h3R2ci';
});

Also, I couldn't help noticing that you can optimize your code size a bit. Right now, your JS code outputs like this:

var ptm = paper.text(13.791304347826, 35, 'me2');
ptm.attr({'font-size':9});
ptm.attr({'href':'ptm_sp.php?ptm_sp=H3R2me2'});

var t = paper.text(13.791304347826, 70, 'R');
t.attr({'font-size':16});

var num = paper.text(13.791304347826, 85, '2');
num.attr({'font-size':9});

// etc.

... which increases with 3 lines per item. However, it could increase with one line per item:

var t = []; // texts
t.push([13.791304347826, 35, 'me2', 9, 'ptm_sp.php?ptm_sp=H3R2me2']);
t.push([13.791304347826, 70, 'R', 16]);
t.push([13.791304347826, 85, '2', 9]);

for(var i = 0; i < t.length; i++){
    var tt = paper.text(t[i][0], t[i][1], t[i][2]);
    var ta = {};
    if(t[i][3]) ta['font-size'] = t[i][3];
    if(t[i][4]) ta['href'] = t[i][3];
    tt.attr(ta);
}

Just a thought! Post your code on Code Review to develop your coding skills - highly recommended! :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!