I have more than 10 buttons on one page, so I only need to write code once to freeze. and because of this i am using jQuery. Read my code.
$(document).ready(function(){ $('.button').hover(function(){ var bc=$(this).css('background-color'); var cl=$(this).css('color'); $(this).css('background-color',cl); $(this).css('color',bc); }); });
.button { color: #FFFFFF; text-align: center; font-size: 22px; height:70px; width: 160px; margin: 5px; transition: all 0.5s; margin-right:30px; } .button:hover{ transform: scale(1.1); }
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> </script> </head> <body> <button class="button" style="background-color: red;">Hover </button> <button class="button" style="background-color: green;">Hover </button> <button class="button" style="background-color: blue;">Hover </button> </body> </html>
It works fine with one hover, if we constantly hover a button on a button, it means it changes color, so if there is any other way to avoid this? The color should remain the same.
source share