2010-03-01 40 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