• js点击特效动画,小人动画


    1、鼠标点击显示各种表情文字
    onload = function() { var click_cnt = 0; var $html = document.getElementsByTagName("html")[0]; var $body = document.getElementsByTagName("body")[0]; $html.onclick = function(e) { var $elem = document.createElement("b"); $elem.style.color = "#E94F06"; $elem.style.zIndex = 9999; $elem.style.position = "absolute"; $elem.style.select = "none"; var x = e.pageX; var y = e.pageY; $elem.style.left = (x - 10) + "px"; $elem.style.top = (y - 20) + "px"; clearInterval(anim); switch (++click_cnt) { case 10: $elem.innerText = "OωO"; break; case 20: $elem.innerText = "(๑•́ ∀ •̀๑)"; break; case 30: $elem.innerText = "(๑•́ ₃ •̀๑)"; break; case 40: $elem.innerText = "(๑•̀_•́๑)"; break; case 50: $elem.innerText = "( ̄へ ̄)"; break; case 60: $elem.innerText = "(╯°口°)╯(┴—┴"; break; case 70: $elem.innerText = "૮( ᵒ̌皿ᵒ̌ )ა"; break; case 80: $elem.innerText = "╮(。>口<。)╭"; break; case 90: $elem.innerText = "( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃"; break; case 100: case 101: case 102: case 103: case 104: case 105: $elem.innerText = "(ꐦ°᷄д°᷅)"; break; default: $elem.innerText = "❤"; break; } $elem.style.fontSize = Math.random() * 10 + 8 + "px"; var increase = 0; var anim; setTimeout(function() { anim = setInterval(function() { if (++increase == 150) { clearInterval(anim); $body.removeChild($elem); } $elem.style.top = y - 20 - increase + "px"; $elem.style.opacity = (150 - increase) / 120; }, 8); }, 70); $body.appendChild($elem); }; };

     2、鼠标点击烟花效果

    <script type="text/javascript">
            var fgm = {
                on: function (element, type, handler) {
                    return element.addEventListener ? element.addEventListener(type, handler, false) : element.attachEvent("on" + type, handler)
                },
                un: function (element, type, handler) {
                    return element.removeEventListener ? element.removeEventListener(type, handler, false) : element.detachEvent("on" + type, handler)
                },
                bind: function (object, handler) {
                    return function () {
                        return handler.apply(object, arguments)
                    }
                },
                randomRange: function (lower, upper) {//产生范围在lower~upper的随机数
                    return Math.floor(Math.random() * (upper - lower + 1) + lower)
                },
                getRanColor: function () {//随机获得十六进制颜色
                    var str = this.randomRange(0, 0xFFFFFF).toString(16);
                    while (str.length < 6) str = "0" + str;
                    return "#" + str
                }
            };
            //初始化对象
            function FireWorks() {
                this.type = 0;
                this.timer = null;
                this.fnManual = fgm.bind(this, this.manual)
            }
            FireWorks.prototype = {
                initialize: function () {
                    clearTimeout(this.timer);
                    fgm.un(document, "click", this.fnManual);
                    switch (this.type) {
                        case 1:
                            fgm.on(document, "click", this.fnManual);
                            break;
                    }
                    ;
                },
                manual: function (event) {
                    event = event || window.event;
                    this.__create__({
                        x: event.clientX,
                        y: event.clientY
                    });
                },
                __create__: function (param) {
                    //param即鼠标点击点(即烟花爆炸点)
                    var that = this;
                    var oChip = null;
                    var aChip = [];
                    var timer = null;
                    var oFrag = document.createDocumentFragment();
                    (function () {
                        //在50-100之间随机生成碎片
                        //由于IE浏览器处理效率低, 随机范围缩小至20-30
                        //自动放烟花时, 随机范围缩小至20-30
                        // var len = (/msie/i.test(navigator.userAgent) || that.type == 2) ? fgm.randomRange(20, 30) : fgm.randomRange(50, 100)
                        var len = (/msie/i.test(navigator.userAgent) || that.type == 2) ? fgm.randomRange(5, 10) : fgm.randomRange(10, 20)
                        //产生所有烟花爆炸颗粒实体
                        for (i = 0; i < len; i++) {
                            //烟花颗粒形态实体
                            oChip = document.createElement("div");
                            with (oChip.style) {
                                position = "absolute";
                                top = param.y + document.body.scrollTop + "px";
                                left = param.x + "px";
                                width = "4px";
                                height = "4px";
                                overflow = "hidden";
                                borderRadius = "4px";
                                background = fgm.getRanColor();
                            }
                            ;
                            oChip.speedX = fgm.randomRange(-10, 10);
                            oChip.speedY = fgm.randomRange(-10, 10);
                            oFrag.appendChild(oChip);
                            aChip[i] = oChip
                        }
                        ;
                        document.body.appendChild(oFrag);
                        timer = setInterval(function () {
                            for (i = 0; i < aChip.length; i++) {
                                var obj = aChip[i];
                                with (obj.style) {
                                    // top = obj.y + obj.speedY + "px";
                                    // console.log(document.body.scrollTop);
                                    // console.log(document.body.scrollHeight+"ww");
                                    // console.log(obj.offsetTop);
                                    top = obj.offsetTop + obj.speedY + "px";
                                    left = obj.offsetLeft + obj.speedX + "px";
                                }
                                ;
                                obj.speedY++;
                                //判断烟花爆炸颗粒是否掉落至窗体之外,为真则remove
                                //splice() 方法可删除从 index 处开始的零个或多个元素
                                (obj.offsetTop < 0 || obj.offsetLeft < 0 || obj.offsetTop > document.documentElement.clientHeight + document.body.scrollTop || obj.offsetLeft > document.documentElement.clientWidth) && (document.body.removeChild(obj), aChip.splice(i, 1))
                            }
                            ;
                            //判断烟花爆炸颗粒是否全部remove,为真则clearInterval(timer);
                            !aChip[0] && clearInterval(timer);
                        }, 30)
                    })();
                }
            };
    
            fgm.on(window, "load", function () {
                var oFireWorks = new FireWorks();
                oFireWorks.type = 1;
                oFireWorks.initialize();
            });
    
            fgm.on(document, "contextmenu", function (event) {
                var oEvent = event || window.event;
                oEvent.preventDefault ? oEvent.preventDefault() : oEvent.returnValue = false
            });
        </script>


    /*右侧滑动小人*/
    .spig {display:block;156px;height:270px;position:absolute;bottom: 300px;left:180px;z-index:9999;}
    #message{color :#191919;border: 1px solid #c4c4c4;background:#ddd;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;min-height:1em;padding:5px;top:-45px;position:absolute;text-align:center;auto !important;z-index:10000;-moz-box-shadow:0 0 15px #eeeeee;-webkit-box-shadow:0 0 15px #eeeeee;border-color:#eeeeee;box-shadow:0 0 15px #eeeeee;outline:none;font-size:0.8rem}
    .mumu{9.75rem;height:15.46rem;cursor: move;background:url(https://blog-static.cnblogs.com/files/ggymx/gril.gif) no-repeat;background-size:100% 100%}

    
    

    <!--博客精灵 start*-->
    <div id="spig" class="spig">
    <div id="message">……</div>
    <div id="mumu" class="mumu"></div>
    </div>




    var isindex=true; var title=""; var visitor="这位怪蜀黍"; //根据分辨率调整小人位置 var addHeight; if(window.screen.height=='1080'){ addHeight= 350; }else{ addHeight= 150; } //右键菜单 jQuery(document).ready(function ($) { $("#spig").mousedown(function (e) { if(e.which==3){ showMessage("秘密通道:<br /> <img src="http://pic.sc.chinaz.com/Files/pic/Listfaces/3646/02.gif"/><br/><a href="https://www.cnblogs.com/ggymx" title="放杨的猩猩">放杨的猩猩</a> ",10000); } }); $("#spig").bind("contextmenu", function(e) { return false; }); }); //鼠标在消息上时 jQuery(document).ready(function ($) { $("#message").hover(function () { $("#message").fadeTo("100", 1); }); }); //鼠标在上方时 jQuery(document).ready(function ($) { //$(".mumu").jrumble({rangeX: 2,rangeY: 2,rangeRot: 1}); $(".mumu").mouseover(function () { $(".mumu").fadeTo("300", 0.3); msgs = ["我隐身了,你看不到我", "我会隐身哦!嘿嘿!", "别动手动脚的,把手拿开!", "把手拿开我才出来!"]; var i = Math.floor(Math.random() * msgs.length); showMessage(msgs[i]); }); $(".mumu").mouseout(function () { $(".mumu").fadeTo("300", 1) }); }); //开始 jQuery(document).ready(function ($) { if (isindex) { //如果是主页 var now = (new Date()).getHours(); if (now > 0 && now <= 6) { showMessage(visitor + ' 你是夜猫子呀?还不睡觉,明天起的来么你?', 6000); } else if (now > 6 && now <= 11) { showMessage(visitor + ' 早上好,早起的鸟儿有虫吃噢!早起的虫儿被鸟吃,你是鸟儿还是虫儿?嘻嘻!', 6000); } else if (now > 11 && now <= 14) { showMessage(visitor + ' 中午了,吃饭了么?不要饿着了,饿死了谁来挺我呀!', 6000); } else if (now > 14 && now <= 18) { showMessage(visitor + ' 中午的时光真难熬!还好有你在!', 6000); } else { showMessage(visitor + ' 快来逗我玩吧!', 6000); } } else { showMessage('欢迎' + visitor + '来到《' + title + '》', 6000); } console.log('屏幕分辨率---------',window.screen.height) $(".spig").animate({ top:$(".spig").offset().top+addHeight, left: 100 }, { queue: false, duration: 1000 }); }); //鼠标在某些元素上方时 jQuery(document).ready(function ($) { $('h2 a').click(function () {//标题被点击时 showMessage('萌萌地加载《<span style="color:#0099cc;">' + $(this).text() + '</span>》中,请稍候'); }); $('h2 a').mouseover(function () { showMessage('要看看《<span style="color:#0099cc;">' + $(this).text() + '</span>》这篇随笔么?'); }); $('#prev-page').mouseover(function(){ showMessage('要翻到上一页吗?'); }); $('#next-page').mouseover(function(){ showMessage('要翻到下一页吗?'); }); $('#index-links li a').mouseover(function () { showMessage('去 <span style="color:#0099cc;">' + $(this).text() + '</span> 逛逛'); }); $('.tbCommentBodys').mouseover(function () { showMessage('<span style="color:#0099cc;">' + visitor + '</span> 向评论栏出发吧!'); }); $('#submit').mouseover(function () { showMessage('确认提交了么?'); }); $('#s').focus(function () { showMessage('输入你想搜索的关键词再按Enter(回车)键就可以搜索啦!'); }); $('#go-prev').mouseover(function () { showMessage('点它可以后退哦!'); }); $('#go-next').mouseover(function () { showMessage('点它可以前进哦!'); }); $('#refresh').mouseover(function () { showMessage('点它可以重新载入此页哦!'); }); $('#go-home').mouseover(function () { showMessage('点它就可以回到首页啦!'); }); $('#addfav').mouseover(function () { showMessage('点它可以把此页加入书签哦!'); }); $('#nav-two a').mouseover(function () { showMessage('嘘,从这里可以进入控制面板的哦!'); }); $('.post-category a').mouseover(function () { showMessage('点击查看此分类下得所有文章'); }); $('.post-heat a').mouseover(function () { showMessage('点它可以直接跳到评论列表处.'); }); $('#tho-shareto span a').mouseover(function () { showMessage('你知道吗?点它可以分享本文到'+$(this).attr('title')); }); $('#switch-to-wap').mouseover(function(){ showMessage('点击可以切换到手机版博客版面'); }); }); //无聊讲点什么 jQuery(document).ready(function ($) { window.setInterval(function () { msgs = [ "陪我聊天吧!", "好无聊哦,你都不陪我玩!", "…@……!………", "^%#&*!@*(&#)(!)(", "我可爱吧!嘻嘻!~^_^!~~","谁淫荡呀?~谁淫荡?,你淫荡呀!~~你淫荡!~~","从前有座山,山上有座庙,庙里有个老和尚给小和尚讲故事,讲:“从前有座……”"]; var i = Math.floor(Math.random() * msgs.length); showMessage(msgs[i], 8000); }, 15000); }); //评论资料 jQuery(document).ready(function ($) { $("#author").click(function () { showMessage("留下你的尊姓大名!"); $(".spig").animate({ top: $("#author").offset().top - 70, left: $("#author").offset().left - 170 }, { queue: false, duration: 1000 }); }); $("#email").click(function () { showMessage("留下你的邮箱,不然就是无头像人士了!"); $(".spig").animate({ top: $("#email").offset().top - 70, left: $("#email").offset().left - 170 }, { queue: false, duration: 1000 }); }); $("#url").click(function () { showMessage("快快告诉我你的家在哪里,好让我去参观参观!"); $(".spig").animate({ top: $("#url").offset().top - 70, left: $("#url").offset().left - 170 }, { queue: false, duration: 1000 }); }); $("#tbCommentBody").click(function () { showMessage("认真填写哦!不然会被认作垃圾评论的!我的乖乖~"); $(".spig").animate({ top: $("#tbCommentBody").offset().top - 70, left: $("#tbCommentBody").offset().left - 170 }, { queue: false, duration: 1000 }); }); }); var spig_top = 50; //滚动条移动 jQuery(document).ready(function ($) { var f = $(".spig").offset().top; $(window).scroll(function () { $(".spig").animate({ top: $(window).scrollTop() + f +addHeight }, { queue: false, duration: 1000 }); }); }); //鼠标点击时 jQuery(document).ready(function ($) { var stat_click = 0; $(".mumu").click(function () { stat_click++; if (stat_click > 4) { msgs = ["你有完没完呀?", "你已经摸我" + stat_click + "次了", "非礼呀!救命!OH,My ladygaga"]; var i = Math.floor(Math.random() * msgs.length); //showMessage(msgs[i]); } else { msgs = ["筋斗云!~我飞!", "我跑呀跑呀跑!~~", "别摸我,大男人,有什么好摸的!", "惹不起你,我还躲不起你么?", "不要摸我了,我会告诉老婆来打你的!", "干嘛动我呀!小心我咬你!"]; var i = Math.floor(Math.random() * msgs.length); //showMessage(msgs[i]); } s = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6,0.7,0.75,-0.1, -0.2, -0.3, -0.4, -0.5, -0.6,-0.7,-0.75]; var i1 = Math.floor(Math.random() * s.length); var i2 = Math.floor(Math.random() * s.length); $(".spig").animate({ left: document.body.offsetWidth/2*(1+s[i1]), top: document.body.offsetheight/2*(1+s[i1]) }, { duration: 500, complete: showMessage(msgs[i]) }); }); }); //显示消息函数 function showMessage(a, b) { if (b == null) b = 10000; jQuery("#message").hide().stop(); jQuery("#message").html(a); jQuery("#message").fadeIn(); jQuery("#message").fadeTo("1", 1); jQuery("#message").fadeOut(b); }; //拖动 var _move = false; var ismove = false; //移动标记 var _x, _y; //鼠标离控件左上角的相对位置 jQuery(document).ready(function ($) { $("#spig").mousedown(function (e) { _move = true; _x = e.pageX - parseInt($("#spig").css("left")); _y = e.pageY - parseInt($("#spig").css("top")); }); $(document).mousemove(function (e) { if (_move) { var x = e.pageX - _x; var y = e.pageY - _y; var wx = $(window).width() - $('#spig').width(); var dy = $(document).height() - $('#spig').height(); if(x >= 0 && x <= wx && y > 0 && y <= dy) { $("#spig").css({ top: y, left: x }); //控件新位置 ismove = true; } } }).mouseup(function () { _move = false; }); });

      

  • 相关阅读:
    学会时刻总结
    JS银行卡号Luhm校验
    来京一年总结
    Linux内核同步机制 第1部分(转)
    Spinlock 简介(转)
    warning: no newline at end of file 解决(转)
    c语言 关键字 extern(转)
    MFC 线程同步(转)
    C语言 全局变量 初始化
    Linux 内核的同步机制,第 2 部分
  • 原文地址:https://www.cnblogs.com/wasbg/p/11692338.html
Copyright © 2020-2023  润新知