简体   繁体   English

悬停时将徽标更改为颜色

[英]Change logo to colour on hover

I am using a WordPress theme called vigor.我正在使用一个名为 vigor 的 WordPress 主题。 I was wondering if I could have my logo in grey scale, and once I hover over the logo it would change in to a colour version.我想知道我是否可以使用灰度徽标,一旦我将鼠标悬停在徽标上,它就会变成彩色版本。 How can this be done.如何才能做到这一点。 In my theme menu I have a place for custom CSS and jQuery.在我的主题菜单中,我有一个自定义 CSS 和 jQuery 的位置。 I also have both versions in a PNG.我也有两个版本的 PNG。

Yes, this is possible! 是的,这是可能的! No need for seperate PNG images. 无需单独的PNG图片。

You can use the following code, with CSS filters: 您可以将以下代码与CSS过滤器一起使用:

HTML: HTML:

<img id="logo" src="http://lorempixel.com/400/200/">

CSS: CSS:

#logo {
    -webkit-filter: grayscale(100%);
    -webkit-transition: .5s ease-in-out;
    -moz-filter: grayscale(100%); 
    -moz-transition: .5s ease-in-out;
    -o-filter: grayscale(100%); 
    -o-transition: .5s ease-in-out;
}

#logo:hover {
    -webkit-filter: grayscale(0%);
    -webkit-transition: .5s ease-in-out;
    -moz-filter: grayscale(0%);
    -moz-transition: .5s ease-in-out;
    -o-filter: grayscale(0%);
    -o-transition: .5s ease-in-out;
} 

JSFiddle example JSFiddle示例

You can use the CSS 3 Filters. 您可以使用CSS 3过滤器。 Try this. 尝试这个。

https://jsfiddle.net/1fog16gn/ https://jsfiddle.net/1fog16gn/

#sampleImage {
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%); 
    -o-filter: grayscale(100%); 
}

#sampleImage:hover {
    -webkit-filter: grayscale(0%);
    -moz-filter: grayscale(0%);
    -o-filter: grayscale(0%);
}

Try this:试试这个:

/* change image on hover */
a.Header-branding:hover img {
    visibility: hidden;
}
a.Header-branding:hover {
    background-image: url(https://beaverhero.com/wp-content/uploads/2019/06/trees-3464777_640-min.jpg);
    background-size: cover;`enter code here`
    background-repeat:no-repeat;
}

你可以这样

#logo:hover { background-image:url('color-1.png') }

#logo { background-image:url('color-2.png') }

I have been using this this jquery plugin: https://github.com/karlhorky/gray for images grayscale. 我一直在使用这个jQuery插件: https : //github.com/karlhorky/gray用于灰度图像。 It's easy to use and implement as you only need to add grayscale class to an image or grayscale grayscale-fade for hover effect. 它很容易使用和实现,因为您只需要将灰度类添加到图像或灰度淡入淡出以产生悬停效果。 I've used this plugin in may projects, because the css filters do not work in all browsers, mainly Internet explorer and I have checked many grayscale plugins out there to find the one that really gets the job done and I've been sticking to this one. 我在May项目中使用了此插件,因为css过滤器无法在所有浏览器(主要是Internet Explorer)中运行,并且我检查了许多灰度插件以找到能够真正完成工作的插件,而我一直坚持这个。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM