我試圖與水平梯度的菜單欄。我使用-webkit-background-clip
取得了一些成功,但在Firefox中無法使用。梯度文本跨瀏覽器
我發現一個jQuery插件pxgradient這是跨瀏覽器兼容的,但我不能讓它跨越梯度幾個li
元素。請參閱以下的jsfiddle:
http://jsfiddle.net/vnv4nyhj/10/
function gradient1() {
$(".test").pxgradient({
step: 10,
colors: ["#ff0066", "#2850FF"],
dir: "x"
});
};
我想要的梯度更像頂一個。理想情況下,我希望邊框底部包含相同的懸停漸變,但我可能生活在沒有這個的世界中。
PS-的font-awesome
圖標是存在的,只是因爲它給了我前面的問題,所以我現在包括,以確保它的工作原理。
更新: 另一種可能的想法,我用了讀元素的數量,然後除以每個元素的顏色,並使用第n個孩子()選擇每種顏色指定播放。
<script>
//Get number of list items
var menuItems = $("li").children().length;
//Convert colors to hex
hexString1 = '2850FF';
hexString2 = 'FF0066';
color1 = parseInt(hexString1, 16);
color2 = parseInt(hexString2, 16);
//Calculate difference in colors and color step
colorDifference = color2 - color1;
colorStep = colorDifference/(menuItems - 1);
colorStep = parseInt(colorStep);
//Loop through elements and apply gradients
for (i = 0; i < menuItems; i++) {
newColor1 = color1 + (i * colorStep);
newColor2 = color1 color2 -1;
gradientStart = newColor1.toString(16);
gradientEnd = newColor2.toString(16);
//use gradientStart and gradientEnd as colors in the function, not sure on this part yet
}
</script>
雖然這似乎是如此矯枉過正,但必須有一個更簡單的解決方案?與具有幾個字符的元素相比,具有許多字符的元素也將具有相對較慢的漸變。這可以通過計算每個元素的字符數來解決,但它看起來效率相當低。
嗯,你的小提琴瞎搞我刪除從中使文本看起來像你想要的鏈接HREF屬性,但是當我試圖pxgradiant呼叫作出後注入URL,它不工作。 [你可以在這裏看到](http://jsfiddle.net/vnv4nyhj/11/)如果找到工作或其他方式,生病讓你知道。 – crazymatt
謝謝你看看。 我有一個不同的想法,但我怎樣才能用普通的編輯器回答我自己的問題? stackoverlow的長時間讀者,第一次海報。 – Robert
@羅伯特編輯你的問題,如果你需要澄清的東西。如果您在查找時遇到問題,編輯「按鈕」位於標籤下方。 –