Home > Article > Web Front-end > Implementation of mouse-responsive transparency gradient effect
This time I will bring you the implementation of the mouse-responsive transparency gradient effect. What are the precautions for making the mouse-responsive transparency gradient effect? The following is a practical case, let's take a look.
The example in this article describes jQuery's implementation of mouse-responsive transparency gradient animation effect. Share it with everyone for your reference, the details are as follows: Let’s take a look at the running effect first:##The specific code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>js动画-透明度变化</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.js"></script> <style> * { margin: 0; padding: 0; font-family:"微软雅黑" } #box{ height:100px; width:100px; background-color:#0099CC; margin-top:200px; position:relative; /*透明度变化*/ left:0px; filter:alpha(opacity:30); opacity:0.3; } span{ display:block; color:blue; width:25px; height:100px; background-color:#FFFF99; position:absolute; left:100px; } </style> </head> <body> <p id="box"> <span>移动</span> </p> <script> window.onload=function(){ var p1=document.getElementById("box"); p1.onmouseover=function(){ startMove(100); } p1.onmouseout=function(){ startMove(30); } } var timer=null; var alpha=30; function startMove(itarget){ clearInterval(timer); var p1=document.getElementById("box"); timer=setInterval(function(){ var speed=0; if(alpha>itarget){ speed=-10; }else{ speed=10; } if(alpha==itarget){ clearInterval(timer); }else{ alpha+=speed; p1.style.filter="alpha(opacity:"+alpha+")"; p1.style.opacity=alpha/100; } },100) } </script> </body> </html>
I believe it After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
How to use jquery to create a magnifying glass effectjquery adds HTML tags with stylesHow does jQuery get the value of the label sub-elementHow does jQuery create an animation effect that bounces when it hits the edge of the frameThe above is the detailed content of Implementation of mouse-responsive transparency gradient effect. For more information, please follow other related articles on the PHP Chinese website!