Home >Web Front-end >JS Tutorial >Javascript implements color gradient changes and gradient effect code_javascript skills
I want to do something about the navigation bar of this site. Therefore, I chose to use js to change the gradient of the color of the navigation bar.
At first, I thought of using the opacity attribute (transparency) to change the gradient of the color. However, there is a problem.
Each navigation label uses [li]. When the mouse floats over the label, the className of [li] is immediately changed through onmouseover(), and setInterval() is used to change its opacity from 0 to 1. .However, when the mouse leaves, it seems to be a lot more troublesome to restore the color of the [li] tag. Therefore, I quickly gave up this approach and changed my mind.
I searched on Baidu and saw a good article at http://www.cnblogs.com/cloudgamer/archive/
2009/03/11/color.html. Subsequently, simplifications were made and a solution was found.
It is better to first pass two color values, such as "#FFFFFF" and "#CCCCCC", one of which is the starting color and the other is the ending color. Through processing, various color strings are obtained when the two colors change, and the number of strings, that is, the frequency of acquisition, can be adjusted. Return to an array variable, the code is as follows: