S
S
Sergey questions2018-02-25 14:52:43
css
Sergey questions, 2018-02-25 14:52:43

Who can help implement the js function?

I apologize for the title, but I don't even know how to call the topic otherwise.

I made such a simple script: https://jsfiddle.net/ordzb831/8/
The point is that the button smoothly changes color (in this case, there will be a transformation in the future, etc.).
The problem is that I figured out how to do this when the cursor is inside a block, but the color changes when we move the cursor from the extreme left side of the block .boxto the extreme right.

The task is to make the button change color when the cursor approaches it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aloky, 2018-02-25
@smartycms

$(document).on('mousemove','.box',function(e) {
    var y = e.clientY/$(".box").height();
    var x = e.clientX/$(".box").width();
    var sum = (x + y) / 2;
    $(".krug").css({background: "rgba(43, 122, 245, "+sum+")"});
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question