0

hey people I got this code in jQuery:

function onRight() {
  $(this).css(
    'background',
    'linear-gradient(to right, rgb(255, 255, 255), rgb(196, 196, 196)'
  );
}

works good but I got a problem, the change is too fast. how can I make it looks like fadeIn? or just use any duration to slow it down?

** cant do it with css because its gradient.

thanks by heart

rio
  • 757
  • 5
  • 19
  • 32

2 Answers2

0

This is perfectly achievable via CSS alone:- As shown by Ana Tudor Here : https://codepen.io/thebabydino/pen/jBbXPP

/* <- Demo Stuff Start */

body{
  font-family: 'Montserrat', sans-serif;
  margin:0;
}

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  width: 80vw;
  margin: 0 auto;
  min-height: 100vh;
}
.btn {
  flex: 1 1 auto;
  margin: 10px;
  padding: 30px;
  text-align: center;
  text-transform: uppercase;
  transition: 0.5s;
  background: linear-gradient(90deg, var(--c1, #f6d365), var(--c2, #fda085) 51%, var(--c1, #f6d365)) var(--x, 0)/ 200%;
  color: white;
 /* text-shadow: 0px 0px 10px rgba(0,0,0,0.2);*/
  box-shadow: 0 0 20px #eee;
  border-radius: 10px;
 }

/* Demo Stuff End -> */

/* <- Magic Stuff Start */

.btn:hover { --x: 100%; }

.btn-1 {
  --c1: #f6d365;
  --c2: #fda085;
}

.btn-2 {
  --c1: #fbc2eb;
  --c2: #a6c1ee;
}

.btn-3 {
  --c1: #84fab0;
  --c2: #8fd3f4;
}

.btn-4 {
  --c1: #a1c4fd;
  --c2: #c2e9fb;
}

.btn-5 {
  --c1: #ffecd2;
  --c2: #fcb69f;
}

/* Magic Stuff End -> */
<div class="container">
  <a class="btn btn-1">Hover me</a>
  <a class="btn btn-2">Hover me</a>
  <a class="btn btn-3">Hover me</a> 
  <a class="btn btn-4">Hover me</a> 
  <a class="btn btn-5">Hover me</a>
</div>
Aaron McGuire
  • 1,217
  • 10
  • 14
0

a webkit-transition should do it. change the 0.5s to how long you want it to take. 1.0 for a second or 1.5 for 1.5 seconds etc. this is not the most efficient way but it a quick solution to the problem and easy to implement.

function onRight() {
    $(this).css(
    '-webkit-transition","all 0.5s ease',
    'background',
    'linear-gradient(to right, rgb(255, 255, 255), rgb(196, 196, 196)'
    );
}
Stefan T
  • 111
  • 8