简体   繁体   中英

How to create colored image mouseover on black/white images (in JQuery)

I'm wondering if there are any good solutions available for turning a color image into a black/white solid state and allowing it to transition back into a colored image on mouse over using jQuery?

I tried a CSS method as described here: Image Greyscale with CSS & re-color on mouse-over? , but I'm not having much luck with it.

Here is the current site: http://frixel.com/wp/ - I am trying to create the effect on the gallery grid.

Hey you are talking about CSS filters... this what you need add this code to your main stylesheet file ;)

.portfolio:hover {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;
-webkit-filter: grayscale(1);
}

Use this below code, It helps to create colored image mouseover on black/white image.:

<style>
.blk-white{-webkit-filter: grayscale(100%); filter: grayscale(100%);}
</style>
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<script type="text/javascript">
function display_blackwhite(obj) {
$(obj).addClass("blk-white");
}
function display_colorphoto(obj) {
$(obj).removeClass("blk-white");
}
</script>
</head>
<body>
<img src="change-colorphoto-black-white1.jpg" onMouseOver="display_blackwhite(this)" onMouseOut="display_colorphoto(this)" width="350"/>
<img src="change-colorphoto-black-white2.png" onMouseOver="display_blackwhite(this)" onMouseOut="display_colorphoto(this)" width="350"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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