RaphaëlJS,痛みのコーディング&臭のブラウザ(IE)
質問
アドバイスを必要約、ベスト-アプローチはこの問題:
私は落ンスが大勢詰め掛け好 RaphaëlJS, ではSVG実現のための符号化では持家の折りにします。
しかし、いようで、また頑張ろうという気持含 .js
ファイル毎にメリットをグラフィックいたいの描画のためのページです。
いつかのインターネットがかなったことも明らかになっています"動的"、そ:(以下は私の編集コードだけ早く送ってくださ http://groups.google.com/group/raphaeljs/msg/ce59df3d01736a6f)
function parseXML(xml) {
if (window.ActiveXObject && window.GetObject) {
var dom = new ActiveXObject('Microsoft.XMLDOM');
dom.loadXML(xml);
return dom;
}
if (window.DOMParser) {
return new DOMParser().parseFromString(xml, 'text/xml');
throw new Error('No XML parser available');
}
}
(function($) {
$.fn.render_raphaels = function(options) {
var defaults, options, counter, img_path, doc, root, vb, dims, img, node, path, atts, container, new_svg, inline;
defaults = {};
options = $.extend(defaults, options);
counter = 0;
inline = false;
// find all the img's that point to SVGs
$('img[src*="\.svg"]').each(function() {
$(this).fadeOut(1000);
img_path = $(this).attr('src');
if (!$(this).attr('id')) new_svg = true;
if ($(this).hasClass('inline')) inline = true;
container = jQuery('<div/>', {
id: $(this).attr('id') ? $(this).attr('id') : 'svg-' + (counter + 1),
'class': $(this).attr('class') ? $(this).attr('class') : 'svg'
}).hide().insertBefore($(this));
$.get(img_path, null, function(doc) {
doc = parseXML(doc);
root = $(doc).find('svg')[0];
dims = [root.getAttribute('width'), root.getAttribute('height')];
if(new_svg) container.css({ width: dims[0], height: dims[1] });
if(inline) container.css('display', 'inline-block');
img = Raphael(container.attr('id'), parseInt(dims[0]), parseInt(dims[1]));
$(root).find('path').each(function() {
node = this;
path = img.path($(this).attr('d'));
$(['stroke-linejoin','stroke','stroke-miterlimit','stroke-width','fill','stroke-linecap']).each(function() {
if($(node).attr(this.toString())) {
path.attr(this, $(node).attr(this.toString()));
} else {
path.attr(this, 0);
}
});
if($(node).attr('style')) {
atts = $(node).attr('style').split(';');
for(var i=0; i < atts.length; i++) {
bits = atts[i].split(':');
path.attr(bits[0],bits[1]);
}
}
});
}, 'text');
$(this).remove(); // removes the original image after the new one has been redrawn
container.fadeIn(2000);
});
};
})(jQuery);
本質的にできるとのことだけ書く通常の画像のタグの .svg
グラフィックのjQueryプラグインは自動的に置き換えるのRaphaël-描画されます。
この作品も非SVG対応ブラウザのように、IEが、現代のブラウザが実際に既に支援SVGグラフィック、画像タグ作品としてではなRaphaël)、Raphaël負荷でunloads既存のイメージを、その薄さRaphaëlバージョン---質を点滅させます。たdownplayことにより色落ちの新しいバージョンが、まだ問題となるのは、非表示、表示します。
しか必要との調整の可能性問題のあるブラウザのように家の望ましくない行動の基準に準拠したブラウザのようにサファリ4およびFirefox3です。でも、こういう仕事がしたいよん大きく変える方というコードがなぜか使えるプラグインの場となる
知っているSVGはまだまだ最先端のがんて思いついで周りを取得す。
免責事項:可能であれば、いままでも近づかないようにしましょうブラウザを対象に...なんと、通常管理で機能的なワークフローの解決ではなく、ブラウザをハック.
2免責事項:い基づいてソリューションFlash;になりたいとして"ネイティブ"としてwebブラウザでjavascriptの実行をするかによります。(このはなぜかとてもワクワクした気持ちいRaphaëlができな場所には近づかないでくださいFlash).
解決 2
右が浮かび上がったこ---(Ruby on Railsを使用すね)
- 輸出SVGグラフィックを
public/images/svg/
- 走
rake svg:parse:to_json
(マレーキタソース) - 再描画のRaphaëlグラフィックを使用JSONパスデータです。
- コマトグラフィックのみを使用
<span class="svg">name_of_svg_file</span>
(sのスパンによるデフォルトのCSSでは、再描画を変更jQueryプラグイン。
これは私のワークフローのイラストレーターからHTMLもしてくれてありがとうございます私のrakeタスクの火災時の私のカピストラーノの展開).これは私のニーズの概要私の質問とこの描画速やちらつきを無くしていくブラウザか試しているRaphaël支持を必要とせず、Flashそのためには、書面でのみ線のコード/トグラフィックの <span>
タグの名前でグラフィック).
Refactorings歓迎いたします。
ToDo:現在、ユーザがjavascriptが無効になっ off, ありません。う簡単に <noscript>
ブロックが教えてくれるので助かりますが...
parse_svg.レーキ
require 'hpricot' # >= 0.8.2
require 'json/pure'
namespace :svg do
namespace :parse do
desc "Parse all SVG graphics in '/public/images/svg' into JSON libraries in '/public/javascripts/raphael/svg-js/' usable by Raphaël"
task :to_json do
FileList['public/images/svg/*.svg'].each do |svg|
name = File.basename(svg).split('.')[0]
doc = open(svg) { |f| Hpricot.XML(f) } # parse the SVG
js = {} # container
js[:name] = name
js[:width] = doc.at('svg')['width'].to_i
js[:height] = doc.at('svg')['height'].to_i
js[:paths] = [] # all paths
doc.search("/svg/g//path").each do |p|
path = {} # our path hash
path[:path] = p['d'].gsub(/(?:[\r\n\t])+/, ',')
path[:stroke_width] = p['stroke-width'] || 0
path[:stroke] = p['stroke'] || 0
path[:fill] = p['fill'] || 0
js[:paths] << path
end
File.open("public/javascripts/raphael/svg-js/#{name}.js", 'w') { |f| f.write(js.to_json) }
end
puts "Done!"
end
end
end
render_raphaels.jquery.js
(function($) {
$.fn.render_raphaels = function(options) {
var defaults, options, name, container, raphael;
defaults = {
span_id: 'svg-ref'
};
options = $.extend(defaults, options);
// find all the spans that point to SVGs, based on default or passed-in identifier
$('span.'+options.span_id).each(function() {
name = $(this).text();
$.getJSON('/javascripts/raphael/svg-js/' + name + '.js', function(data) {
paper = Raphael(document.getElementById(data.name), data.width, data.height);
for (var p in data.paths) {
paper.path(data.paths[p].path).attr({
fill: data.paths[p].fill,
stroke: data.paths[p].stroke,
'stroke-width': data.paths[p].stroke_width
});
}
});
// remove the span
$(this).remove();
});
};
})(jQuery);
すべてのページをSVGs
$.fn.render_raphaels({ span_id: 'svg' });
他のヒント
あなたは試したことがあり svgweb の?
ネイティブサポートされていない場合は、、Flashプラグインは、SVGをレンダリングするためにトリガされます。