2010-03-01 110 views
4

任何人都可以提出一种无需使用Flash或Silverlight等任何角度旋转文字的方法。我想用相同角度的文字使用倾斜图像。用Javascript旋转文字

+0

您需要支持哪些浏览器? – SLaks 2010-03-01 22:11:44

+0

IE7 +,FF,Safari – CLiown 2010-03-01 22:16:45

回答

4

这是一个有点晚了,但我已经写了一些代码来做到这一点。

http://jsfiddle.net/73DzT/139/

Object.prototype.rotate = function(d) { 
    var s = "rotate(" + d + "deg)"; 
    if (this.style) { // regular DOM Object 
     this.style.MozTransform = s 
     this.style.WebkitTransform = s; 
     this.style.OTransform = s; 
     this.style.MSTransform = s; 
     this.style.transform = s; 
    } else if (this.css) { // JQuery Object 
     this.css("-moz-transform", s); 
     this.css("-webkit-transform", s); 
     this.css("-o-transform", s); 
     this.css("-ms-transform", s); 
     this.css("transform", s); 
    } 
    this.setAttribute("rotation", d); 
} 

可以与常规的对象或与对象的JQuery使用。并存储一个名为“旋转”的属性,为您提供当前的旋转值。

+0

这几乎可行。:-) 你需要添加一个{display:block}到CSS。否则,链接不会旋转。虽然酷,简单的解决方案! – KateYoak 2012-06-16 06:32:33

+0

更新后感谢:P. – rlemon 2012-06-16 14:25:58