jquery - Gradient text cross browser -
i'm trying make menu bar horizontal gradient. i've had success using -webkit-background-clip
won't work in firefox.
i found jquery plugin pxgradient that's cross browser compatible can't span gradient on several li
elements. see following jsfiddle:
http://jsfiddle.net/vnv4nyhj/10/
function gradient1() { $(".test").pxgradient({ step: 10, colors: ["#ff0066", "#2850ff"], dir: "x" }); };
i want gradient more top one. ideally i'd border-bottom include same gradient on hover can possibly live in world without that.
ps- font-awesome
icon there because gave me problems earlier included make sure works.
update: possible idea playing read number of elements, divide colours per element , use nth-child() selector assign each color.
<script> //get number of list items var menuitems = $("li").children().length; //convert colors hex hexstring1 = '2850ff'; hexstring2 = 'ff0066'; color1 = parseint(hexstring1, 16); color2 = parseint(hexstring2, 16); //calculate difference in colors , color step colordifference = color2 - color1; colorstep = colordifference / (menuitems - 1); colorstep = parseint(colorstep); //loop through elements , apply gradients (i = 0; < menuitems; i++) { newcolor1 = color1 + (i * colorstep); newcolor2 = color1 color2 -1; gradientstart = newcolor1.tostring(16); gradientend = newcolor2.tostring(16); //use gradientstart , gradientend colors in function, not sure on part yet } </script>
it's seems overkill though, there must simpler solution? element many characters have relatively slow gradient compared 1 few characters. possibly fixed counting numbers of characters per element, seems rather inefficient.
an easy solution, work in ff, chrome, , safari, using blend modes.
the trick gradient set under a, in ul .
setting mix-blend-mode: screen, colors show on black places (the text, , border when hovered)
ul { display: inline-block; padding: 0; font-size: 30px; font-weight: bolder; background: linear-gradient(90deg, red, blue); } li { mix-blend-mode: screen; background-color: white; box-shadow: 8px 0px 0px white; } li, li { display: inline-block; text-decoration: none; border-bottom: 3px solid white; } li:hover { border-bottom: 3px solid black; text-shadow: 0px 0px 2px gray; }
<div class="navigation"> <ul> <li><a href="#">nav 1</a></li> <li><a href="#">nav 2</a></li> <li><a href="#">nav 3</a></li> <li><a href="#">nav 4</a></li> <li><a href="#">nav 5</a></li> </ul> </div>
Comments
Post a Comment