博客装饰---鼠标移动、点击效果

昨天看别人博客的时候有很炫酷的效果,我很喜欢,于是决定自己也来弄一哈~这个是需要申请js权限的~没想到昨天申请今天就通过了,非常感谢!

第一个:鼠标随意晃一下都是爱你的形状~~

/*鼠标跟随效果*/
<style type="text/css">
    .draw {
        position: fixed;
        width: 1px;
        line-height: 1px;
        pointer-events: none;
    }
    @keyframes floatOne {
        0% {
                    opacity:1;
        }
        50% {
                    opacity:1;
        }
        100% {
                    opacity:0;
            transform:translate3D(0, -20px, 0) scale(5) rotate(45deg);
        }
    }
</style>
<script type="text/javascript">
    var H = 0;
    $(document).bind(‘mousemove touchmove‘,function(e) {
        e.preventDefault();
        var drawSize = 10;
        var drawType = ‘?‘;
        var floatType = ‘floatOne‘;
        var xPos = e.originalEvent.pageX;
        var yPos = e.originalEvent.pageY;

        $(‘body‘).append(‘<div class="draw" style=" font-size:‘+drawSize+‘px;left:‘+xPos+‘px;top:‘+yPos+‘px;-webkit-animation:‘+floatType+‘ .9s 1;-moz-animation:‘+floatType+‘ .9s 1;color:#FF83FA;">‘+drawType+‘</div>‘);

        $(‘.draw‘).each(function() {
            var div = $(this);
            setTimeout(function() {$(div).remove();},800);
        });
    });
</script>

第二个:点出爆炸形态!

/* 点击爆炸效果*/
<canvas class="fireworks" style="position: fixed; left: 0px; top: 0px; z-index: 1; pointer-events: none; width: 1440px; height: 451px;" width="2880" height="902"></canvas>
<script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>
<script type="text/javascript">
"use strict";function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=0.1,a.alpha=0.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++){e.animatables[t].target.draw()}}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++){n.push(createParticule(e,t))}anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:0.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)}"use strict";function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=0.1,a.alpha=0.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++){e.animatables[t].target.draw()}}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++){n.push(createParticule(e,t))}anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:0.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)};
</script>

第三个:点击出现求赞语句效果,求赞呀~~~

/* 鼠标点击求赞文字特效 */
<script type="text/javascript">
var a_idx = 0;
jQuery(document).ready(function($) {
    $("body").click(function(e) {
        var a = new Array("?喜欢就点个赞呗?","?不是点这里哦?","?快去点赞?","?在文章最下面哦?","?快去推荐一下吧?","?感谢观看?","?");
        var $i = $("<span></span>").text(a[a_idx]);
        a_idx = (a_idx + 1) % a.length;
        var x = e.pageX,
        y = e.pageY;
        $i.css({
            "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
            "top": y - 20,
            "left": x,
            "position": "absolute",
            "font-weight": "bold",
            "color": "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"
        });
        $("body").append($i);
        $i.animate({
            "top": y - 180,
            "opacity": 0
        },
        1500,
        function() {
            $i.remove();
        });
    });
});
</script>

如何装饰呢,这些代码往哪儿放呢~~

上面的三块代码可以直接复制放到我截图的框框里~

给大家推荐下,有好多的js脚本,可以自行借鉴使用~

各种鼠标移动脚本链接

各种鼠标点击脚本链接

这下我也有特效了哈哈哈~~~

其实我真想知道我发的东西到底有没有人看.................

原文地址:https://www.cnblogs.com/wanghao1874/p/10722919.html

时间: 2024-07-30 19:46:38

博客装饰---鼠标移动、点击效果的相关文章

博客园鼠标滑动线条吸附效果

<script> !function(){ function n(n,e,t){ return n.getAttribute(e)||t } function e(n){ return document.getElementsByTagName(n) } function t(){ var t=e("script"),o=t.length,i=t[o-1]; return{ l:o,z:n(i,"zIndex",-1),o:n(i,"opaci

博客园鼠标点击彩蛋特效

博客园是一个很开放的平台,大家都可以在里面美化自己的博客,把自己的博客变得多彩. 鼠标的特效花了我很长的时间,下面我把如何做成“鼠标点击彩蛋特效”告诉大家. 1.应把鼠标点击特效的代码放在哪里 把代码放在页脚Html代码处 2.代码实现 1 <script src="https://blog-static.cnblogs.com/files/yjlblog/cursor-effects.js"></script> 2 <canvas width="

【hugo】- hugo 博客 添加鼠标单击特效

hugo 博客 监听鼠标点击事件,添加动画效果 js下载 链接:https://pan.baidu.com/s/1SZu76WdEXRxLCfqJ2lbbtQ 密码:r056 移入hugo博客中 打开路径下 themes/maupassant/layouts/_default/baseof.html 文件,添加成以下代码 这里的js路径需要根据自己的实际需要引入,我的是放在themes/maupassant/static/js/anime.min.js目录下 有时候会找不到js,是因为confi

用jQuery和css3实现的一个模仿淘宝ued博客左边的菜单切换动画效果

今天看到淘宝ued博客上左边的菜单导航动画效果不错,就用jQuery和css3做了一个简单的例子,主要是实现运用了jQuery 事件和css3 transition属性. 用一个元素来实现鼠标滑动到某个导航的背景效果,文字颜色也运用css3 transition 渐变的效果 当鼠标滑动其他导航的时候,加背景的元素的top值也会随着变化,定位到当前的导航上,同时文字字体颜色也会跟着改变: 主要实现的html代码如下: <div class="menuBox"> <div

在博客添加鼠标特效跟随鼠标移动的线条《转》

原文:http://www.cnblogs.com/Sharley/p/9603129.html 设置方式是在博客的“管理-->设置”,然后在设置中的页脚HTML代码中添加 <script> !function(){ function n(n,e,t){ return n.getAttribute(e)||t } function e(n){ return document.getElementsByTagName(n) } function t(){ var t=e("scr

博客园鼠标点击特效代码

<script type="text/javascript"> /* 鼠标特效 */ var a_idx = 0; jQuery(document).ready(function($) { $("body").click(function(e) { var a = new Array("?富强?","?民主?","?文明?","?和谐?","?自由?",&

博客园鼠标效果:24字社会主义核心价值观

<script type="text/javascript"> $(document).ready(function(){ var a_index = 0; var c_index = 0; $("body").click(function(e){ var a = new Array("富强", "民主", "文明", "和谐", "自由", "

博客园TinyMCE编辑器点击链接直接跳转网站

方法如下,首先打开TinyMCE编辑器,然后再点击编译器下面的html按钮,进入网站代码html编辑界面. 然后将我们需要的网址改成: <a href="我们所需要的网址(前面需要加上相应的http/https协议)">我们所需要的网址(前面需要加上相应的http/https协议)</a> 这里主要用到了html当中锚点的知识,当然你也可以尝试在新的浏览器窗口里进行打开,修改为: <a href="我们所需要的网址(前面需要加上相应的http/h

修改博客园推荐人数增加W效果

今天逛园子,偶然看到最多推荐,有点好奇. F12查看元素,发现是在css中加了一个after,内容中增加了一个"w". 本着娱乐至上的准则,自己也试试.复制以下css到设置自定义css中 #digg_count:after{ content: 'w'; } :after, :before { webkit-box-sizing: border-box; moz-box-sizing: border-box; box-sizing: border-box; }