Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
A
B
C
css
body { display:flex; height:100vh; overflow:hidden; justify-content:center; align-items:center; background-color: #222222; } ul { padding:0; } li { display:inline-block; list-style-type:none; margin:0 20px; } li:nth-child(1) button { background:#F3FFBD; } li:nth-child(2) button { background:#247BA0; } li:nth-child(3) button { background:#FF1654; } button { position:relative; background:rebeccapurple; width:200px; height:200px; border-radius:50%; border:5px solid white; color:white; font-family:Verdana; font-weight:bold; font-size:50px; cursor:pointer; padding:0; }
JavaScript
'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var HoverButton = function () { function HoverButton(el) { _classCallCheck(this, HoverButton); this.el = el; this.hover = false; this.calculatePosition(); this.attachEventsListener(); } HoverButton.prototype.attachEventsListener = function attachEventsListener() { var _this = this; window.addEventListener('mousemove', function (e) { return _this.onMouseMove(e); }); window.addEventListener('resize', function (e) { return _this.calculatePosition(e); }); }; HoverButton.prototype.calculatePosition = function calculatePosition() { TweenMax.set(this.el, { x: 0, y: 0, scale: 1 }); var box = this.el.getBoundingClientRect(); this.x = box.left + box.width * 0.5; this.y = box.top + box.height * 0.5; this.width = box.width; this.height = box.height; }; HoverButton.prototype.onMouseMove = function onMouseMove(e) { var hover = false; var hoverArea = this.hover ? 0.7 : 0.5; var x = e.clientX - this.x; var y = e.clientY - this.y; var distance = Math.sqrt(x * x + y * y); if (distance < this.width * hoverArea) { hover = true; if (!this.hover) { this.hover = true; } this.onHover(e.clientX, e.clientY); } if (!hover && this.hover) { this.onLeave(); this.hover = false; } }; HoverButton.prototype.onHover = function onHover(x, y) { TweenMax.to(this.el, 0.4, { x: (x - this.x) * 0.4, y: (y - this.y) * 0.4, scale: 1.15, ease: Power2.easeOut }); this.el.style.zIndex = 10; }; HoverButton.prototype.onLeave = function onLeave() { TweenMax.to(this.el, 0.7, { x: 0, y: 0, scale: 1, ease: Elastic.easeOut.config(1.2, 0.4) }); this.el.style.zIndex = 1; }; return HoverButton; }(); var btn1 = document.querySelector('li:nth-child(1) button'); new HoverButton(btn1); var btn2 = document.querySelector('li:nth-child(2) button'); new HoverButton(btn2); var btn3 = document.querySelector('li:nth-child(3) button'); new HoverButton(btn3);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>吸引悬停效果-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号