帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 心形,我心飞扬动画效果
心形,我心飞扬动画效果
浏览:701次
-
评论:0次
-
发布时间:2018-08-23
Html
Css
Js
body { margin:0; overflow:hidden; background:#303035; }
var canvas = document.querySelector("canvas"); var ctx = canvas.getContext("2d"); //初始化页面新的数量 var num = 10; var ww = window.innerWidth; var wh = window.innerHeight; var hearts = []; function init() { requestAnimationFrame(render); canvas.width = ww; canvas.height = wh; for (var i = 0; i < num; i++) { hearts.push(new Heart()); } // console.log(hearts) } var timeaur; $("body").on("mousedown", function(event) { var e = event || window.event; var x = e.clientX, y = e.clientY; timeaur = setInterval(function() { console.log(123123) hearts.push(new Heart(x, y)); num++ }, 100) $("body").on("mousemove", function(event) { var e = event || window.event; var x = e.clientX, y = e.clientY; hearts.push(new Heart(x, y)); num++ }) }) $("body").on("mouseup", function() { clearInterval(timeaur) $("body").off("mousemove") }) function Heart(x, y) { if (x) { this.x = x; this.y = y; } else { this.x = Math.random() * ww; this.y = Math.random() * wh; } this.opacity = (Math.random() * 0.5) + 0.5; this.vel = { x: (Math.random() - 0.5) * 4, y: (Math.random() - 0.5) * 4 }; this.targetScale = (Math.random() * 0.15) + 0.02; this.scale = this.targetScale * Math.random(); } Heart.prototype.update = function() { this.x += this.vel.x; this.y += this.vel.y; this.scale += (this.targetScale - this.scale) * 0.01; if (this.x - this.width > ww || this.x + this.width < 0) { this.scale = 0; this.x = Math.random() * ww; } if (this.y - this.height > wh || this.y + this.height < 0) { this.scale = 0; this.y = Math.random() * wh; } this.width = 473.8 * this.scale; this.height = 408.6 * this.scale; } Heart.prototype.draw = function() { ctx.globalAlpha = this.opacity; ctx.drawImage(heartImage, this.x - this.width * 0.5, this.y - this.height * 0.5, this.width, this.height); } function render() { ctx.clearRect(0, 0, ww, wh); // ctx.globalAlpha = 1; // ctx.fillStyle = "rgba(255,255,255,0.3)"; // ctx.fillRect(0, 0, ww, wh); for (var i = 0; i < num; i++) { hearts[i].update(); hearts[i].draw(); } requestAnimationFrame(render); } var heartImage = new Image(); heartImage.onload = init(); heartImage.src = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0NzMuOHB4IiBoZWlnaHQ9IjQwOC42cHgiIHZpZXdCb3g9IjAgMCA0NzMuOCA0MDguNiI+PHBhdGggZmlsbD0iI2QzMjkzMiIgZD0iTTQwNC42LDE2LjZDMzg1LjQsNi4xLDM2My41LDAsMzQwLDBjLTQxLjUsMC03OC41LDE4LjktMTAzLDQ4LjVDMjEyLjMsMTguOSwxNzUuMywwLDEzMy44LDAgYy0yMy4zLDAtNDUuMyw2LjEtNjQuNSwxNi42QzI3LjksMzkuNSwwLDgzLjQsMCwxMzMuOWMwLDE0LjQsMi40LDI4LjMsNi42LDQxLjJDMjkuNiwyNzguNCwyMzcsNDA4LjYsMjM3LDQwOC42IHMyMDcuMi0xMzAuMiwyMzAuMi0yMzMuNWM0LjMtMTIuOSw2LjYtMjYuOCw2LjYtNDEuMkM0NzMuOCw4My40LDQ0NS45LDM5LjYsNDA0LjYsMTYuNnoiLz48L3N2Zz4="; window.addEventListener("resize", function() { ww = window.innerWidth; wh = window.innerHeight; })
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>心形,我心飞扬动画效果-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:心,滑动鼠标出现心形轨迹
用canvas来画心形的,我心飞扬。
按钮点击气泡效果
CSS3+3D相册效果
讨论这个常用代码(0)
回答他人问题或分享心得会奖励牛币
〒_〒 居然一个评论都没有……
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
701
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值