This article mainly introduces jQuery to implement mouse-responsive transparency gradient animation effect, involving jQuery event response and dynamic modification of page element attributes related operating techniques. Friends in need can refer to the following
This article describes the jQuery example Implement 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>
Above I compiled it for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Solution to the option overlay problem of select in layui
Vue.js custom event form input component Method
Summary of several ways for vue to register components
The above is the detailed content of How to use jQuery to implement mouse-responsive transparency gradient animation effect. For more information, please follow other related articles on the PHP Chinese website!