Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

javascript - Is it possible to change between two fontawesome icons on hover?

I have an anchor tag with a font-awesome icon as follows

<a href="#" class="lock"><i class="icon-unlock"></i></a>

Is it possible to change to icon on hover to a different icon?

my CSS

.lock:hover{color:red}

Aside from the icon turning red I'd also like to change the icon to the following

<i class="icon-lock"></i>

Is this possible without the help of JavaScript? Or do I need Javascript/Jquery on hover for this?

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could toggle which one's shown on hover:

HTML:
<a href="#" class="lock">
    <i class="icon-unlock"></i>
    <i class="icon-lock"></i>
</a>
CSS:
.lock:hover .icon-unlock,
.lock .icon-lock {
    display: none;
}
.lock:hover .icon-lock {
    display: inline;
}

Or, you could change the content of the icon-unlock class:

.lock:hover .icon-unlock:before {
    content: "f023";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...