JavaScript JavaScript How to make an image to change color onmouseover? javascript make image clickable,javascript make image appear on click,

I have a button and an image and want them to change color onmouseover. The button changes color fine:

<script>
function secondColor(x) {
x.style.color="#000000";
}
function firstColor(x) {
x.style.color="#ffaacc";
}
</script>

<input onmouseover="secondColor(this)" onmouseout="firstColor(this)" type="submit"><br>

How can I do the same thing with the image? Is there any way:

<img src="..." ...... 

Or do I have to have a second image to replace the first one onmouseover and this is the only way?

Answer:1

If you don't care that much about supporting older browsers, you could use the new CSS3 filter brightness. In chrome, you could write something like this:

var image = document.getElementById('img');

image.addEventListener('mouseover', function() { 
    image.setAttribute('style','-webkit-filter: brightness(1.5)'); 
}, false);

image.addEventListener('mouseout', function() { 
    image.setAttribute('style','-webkit-filter: brightness(1.0)'); 
}, false);

I don't recommend this approach, though. Using another picture while hovering would be a better solution.

Answer:2

I know that this is old, but you don't need two images. Checkout my example using one image.

You can simply change the position of the background image.

<div class="changeColor">&nbsp;</div>

JavaScript

var dvChange = document.getElementsByClassName('changeColor');

 dvChange[0].onmouseover = function(){
   this.style.backgroundPosition = '-400px 0px'; 
 }

dvChange[0].onmouseout = function(){
   this.style.backgroundPosition = '0px 0px'; 
}

CSS

.changeColor{
    background-image:url('http://www.upsequence.com/images/multibg.png');
    width:400px;
    height:400px;
    background-position: 0px 0px;
}

.changeColor:hover{
    background-image:url('http://www.upsequence.com/images/multibg.png');
    width:400px;
    height:400px;
    background-position: -400px 0px;
}

You can also try changing the opacity of the images onmouseover and onmouseout. I don't have an example for that, but its super easy to find and I am sure it has be answered already on stack exchange somewhere.

In the JSFiddle below there is Javascript and non-Javascript examples. http://jsfiddle.net/hallmanbilly/gtf2s8ts/

Enjoy!!

Answer:3

I think you have to use a second image. I recently cam across the following article describing how to do image crossfading on hover using css. Crossfading Image Hover Effect

Answer:4

You can change image SRC on mouse over, you can load two images and use fade effects to "change" them. But better, you can use image as DIV background, make sprite and just move BG on mouse over.

Loading of two different images bring you to disappearing when hover and second image loading. Better do not use JS at all. Make sprite from two images, put it as BG of DIV and write two CSS for DIV, normal and when hover.

Answer:5

Using the bootstrap-tour plug-in (http://bootstraptour.com/), I want to disable or hide the default 'End Tour' button on each step except for the very last step. I tried modifying the step template ...

Using the bootstrap-tour plug-in (http://bootstraptour.com/), I want to disable or hide the default 'End Tour' button on each step except for the very last step. I tried modifying the step template ...

My original (working) code looks like: jQuery().ready(function ($) { $('[id="errorMessages"]').ajaxStart(function () { $(this).html(""); }); $('[id="errorMessages"]').ajaxError(...

My original (working) code looks like: jQuery().ready(function ($) { $('[id="errorMessages"]').ajaxStart(function () { $(this).html(""); }); $('[id="errorMessages"]').ajaxError(...

I am storing html data in my database from the output of a WYSIWYG editor. The html also stores the html for some directives. One of them being the ui-bootstrap tooltip: <span tooltip-placement="...

I am storing html data in my database from the output of a WYSIWYG editor. The html also stores the html for some directives. One of them being the ui-bootstrap tooltip: <span tooltip-placement="...

  1. rendering html angular
  2. render html angular 6
  3. render html angular 7
  4. render html angular 4
  5. render html angular 2
  6. angularjs render html
  7. render html angular 5
  8. render html string angular
  9. render html string angular 6
  10. render html text angular
  11. render raw html angular
  12. render html in angular variable
  13. render html in angular 8
  14. re render html angular
  15. dynamically render html angular
  16. render html in angular component

I want when a user enter 'me' from the prompt text box it will be direct to config.php else print "you don't have access". Below is the code i have so far but is not calling the prompt. Need help on ...

I want when a user enter 'me' from the prompt text box it will be direct to config.php else print "you don't have access". Below is the code i have so far but is not calling the prompt. Need help on ...

  1. prompt with javascript
  2. prompt with options javascript
  3. prompt with password javascript
  4. prompt with input javascript
  5. prompt with checkbox javascript
  6. prompt with button javascript
  7. prompt user with javascript
  8. prompt box with javascript
  9. using prompt with javascript
  10. create prompt with javascript
  11. prompt javascript number
  12. prompt javascript example
  13. prompt javascript w3schools
  14. prompt javascript yes no
  15. prompt javascript mdn
  16. prompt javascript function
  17. prompt javascript cancel
  18. prompt javascript multiple fields
  19. prompt javascript html
  20. prompt javascript not working