用js+css3做一个小球投篮的动画(easing)

<!DOCTYPE html>
<html>
<head>
    <script src="jquery-1.11.3.min.js"></script>
</head>
<body>
    <style>
        @keyframes mycolor{
            10%{
                background:green;
            }
            20%{
                background:red;
            }
            50%{
                background:blue;
            }
            80%{
                background:yellow;
            }
        }
   #test{
      width:30px;
      height:30px;
     transition:all ease 2s 0.2s;
     background:#0094ff;
   }
   #test:hover{
       width:1000px;
       animation:mycolor 2s;
   }
   #water,#water1{
       position:absolute;
       width:10px;
       height:10px;
       border-radius:5px;
       background:red;
       top:400px;
       left:100px;
       cursor:pointer;
   }
   @keyframes myaction{
       80%{
           top:0px;
           left:30px;
       }
       100%{
           top:10px;
       left:10px;
       }
   }
  
    </style>
    <div id="test">

     </div>
    <div id="water1"></div>
    <div id="water"></div>

    <script>
        var i = 0;
        $("#water").click(function () {
            $(this).css("animation", "myaction 1s");
            setTimeout(function () {
                $("#water").removeAttr("style");
            }, 1000);
        });
    </script>
</body>
</html>

这里测试了 CSS3中的新的特性animation,实现了一个简单的移动动画,可以通过这种方式,做出不同的效果,这里只是抛砖引玉。

下面是用JQUERY的esing行为实现的一个,效果更好。

<!DOCTYPE html>
<html>
<head>
    <script src="jquery-1.11.3.min.js"></script>
    <script src="jquery.easing.1.3.js"></script>
</head>
<style>
 #lanzi{
     width:30px;
     height:30px;
     background:blue;
 }
 #qiu{
     width:20px;
     height:20px;
     border-radius:20px;
     position:absolute;
     top:500px;
     left:700px;
     background:red;
 }
</style>
<body>
    <div id="lanzi"></div>
    <div id="qiu"></div>
    <script>
        $(function () {
            $("#qiu").click(function () {
                $("#qiu").animate({
                    top: [0, 'linear'],
                    left: [10, 'easeInExpo']
                }, 1000).animate({
                    top:10,left:10
                },100);
            });
        });
    </script>
</body>
</html>

 

jQuery默认动画

支持toggle()、slideUp()、slideDown()、show()、hide()等jQuery内置的动画效果,使用代码如下:

$(element).slideUp(
    duration: 1000,  
    easing: method,  
    complete: callback 
}); 

参数duration:定义动画运动时间,毫秒,其实就是速度,时间越短,运动速度越快。

参数easing:指定动画效果,Easing js提供多种动画效果,有匀速运动、变加速运动、缓冲波动效果,它们 是:
linear,swing,jswing,easeInQuad,easeOutQuad,easeInOutQuad,easeInCubic, easeOutCubic,easeInOutCubic,
easeInQuart,easeOutQuart,easeInOutQuart, easeInQuint,easeOutQuint,easeInOutQuint,easeInSine,easeOutSine,
easeInOutSine,easeInExpo,easeOutExpo,easeInOutExpo,easeInCirc, easeOutCirc,easeInOutCirc,easeInElastic,
easeOutElastic,easeInOutElastic, easeInBack,easeOutBack,easeInOutBack,easeInBounce,easeOutBounce,easeInOutBounce.

easing的下载地点:
http://gsgd.co.uk/sandbox/jquery/easing/


1. linear2. swing3. easeInQuad4. easeOutQuad5. easeInOutQuad6. easeInCubic7. easeOutCubic8. easeInOutCubic9. easeInQuart10. easeOutQuart11. easeInOutQuart12. easeInQuint13. easeOutQuint14. easeInOutQuint15. easeInExpo16. easeOutExpo17. easeInOutExpo18. easeInSine19. easeOutSine20. easeInOutSine21. easeInCirc22. easeOutCirc23. easeInOutCirc24. easeInElastic25. easeOutElastic26. easeInOutElastic27. easeInBack28. easeOutBack29. easeInOutBack30. easeInBounce    31. easeOutBounce32. easeInOutBounce     

 

<!DOCTYPE html>
<html>
<head>

</head>
<script src="jquery-1.11.3.min.js"></script>
<script src="jquery.easing.1.3.js"></script>
<style>
    #lanzi{
        background:blue;
        width:30px;
        height:30px;
    }
    #qiu{
        background:red;
        width:20px;
        height:20px;
        border-radius:10px;
        position:absolute;
        top:400px;
        left:500px;
    }
</style>
<body>
 <div id="lanzi"></div>
    <div id="qiu"></div>
    <script>
        $("#qiu").click(function () {
            $(this).clone().appendTo('body').animate({
                top: [10, "easeOutCirc"],
                left: [10, "linear"]
            }, 1000, function () { $(this).fadeOut(5000) })
        })
    </script>
</body>
</html>

 

转载于:https://www.cnblogs.com/lunawzh/p/4846448.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要生成一个放烟花的页面,你需要使用HTML,CSS和JS。 HTML用来创建网页的结构,在这里可以创建一个容器来存放烟花的动画效果。 CSS用来设置网页的样式,比如背景颜色、字体、颜色等。 JS用来创建烟花的动画效果,可以通过使用JS库,例如Canvas或SVG,来实现这个效果。 以下是一个简单的HTML和JS代码示例: ```html <!DOCTYPE html> <html> <head> <style> #fireworks { background-color: black; height: 100%; width: 100%; } </style> </head> <body> <div id="fireworks"></div> <script> const canvas = document.getElementById("fireworks"); const ctx = canvas.getContext("2d"); let particles = []; function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); for (let i = 0; i < particles.length; i++) { const particle = particles[i]; particle.update(); ctx.beginPath(); ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2); ctx.fillStyle = particle.color; ctx.fill(); } requestAnimationFrame(draw); } class Particle { constructor(x, y) { this.x = x; this.y = y; this.color = "white"; this.radius = Math.random() * 2 + 1; this.velocity = { x: Math.random() * 4 - 2, y: Math.random() * -5 - 5, }; } update() { this.x += this.velocity.x; this.y += this.velocity.y; this.radius -= 0.01; if (this.radius > 0) { particles.push(new Particle(this.x, this.y)); } } } canvas.addEventListener("click", (e) => { particles.push(new Particle(e.clientX, e.clientY)); }); draw(); </script> </body> </html ### 回答2: 生成一个放烟花的页面需要使用HTML、CSS和JavaScript来实现。以下是一个简单的示例: HTML部分: ```html <!DOCTYPE html> <html> <head> <title>放烟花的页面</title> <style> #fireworks { position: relative; width: 100%; height: 100%; } .firework { position: absolute; width: 10px; height: 10px; background-color: yellow; border-radius: 50%; animation: fireworks 1s infinite; } @keyframes fireworks { 0% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.1); } } </style> </head> <body> <div id="fireworks"></div> <script src="script.js"></script> </body> </html> ``` CSS部分定义了放烟花的样式,使用绝对定位将烟花放置在页面上。每个烟花使用圆形的形状,并使用动画使其从初始状态逐渐缩小消失。 JavaScript部分: ```javascript window.addEventListener("DOMContentLoaded", function() { var fireworksContainer = document.getElementById("fireworks"); function createFirework() { var firework = document.createElement("div"); firework.className = "firework"; firework.style.left = Math.random() * 100 + "%"; firework.style.top = Math.random() * 100 + "%"; fireworksContainer.appendChild(firework); setTimeout(function() { firework.remove(); }, 1000); } setInterval(createFirework, 100); }); ``` JavaScript部分通过监听DOMContentLoaded事件来确保在页面完全加载后执行代码。在createFirework函数中,我们创建一个新的烟花元素,并设置其随机的位置。然后将烟花添加到fireworks容器中,并在一定时间后将其移除,以避免页面上出现太多的烟花。 通过将上述代码保存为HTML、CSS和JavaScript文件,您就可以打开生成一个放烟花的页面。 ### 回答3: 在 HTML 中可以创建一个用于放置烟花的容器,可以使用 `<div>` 元素并为其设置一个特定的 `id`,例如 `fireworks-container`。在 CSS 中,我们可以为这个容器设置比较大的宽度和高度,并为其背景添加一个透明的图片或渐变效果,以模拟夜空的感觉。例如: ```html <div id="fireworks-container"></div> ``` ```css #fireworks-container { width: 800px; height: 600px; background: url('night_sky.jpg') no-repeat center center; background-size: cover; } ``` 然后,我们可以使用 JavaScript 来创建烟花的效果。通过动态创建新的 `<div>` 元素作为烟花,为其设置随机的初始位置、颜色和大小,并将其添加到容器中。然后,使用 CSS3 中的动画效果,将烟花的大小逐渐增加并向上移动,模拟烟花的爆炸效果。同时,还可以添加粒子效果来增加烟花的真实感。 ```javascript function createFirework() { var firework = document.createElement('div'); // 设置烟花的初始位置、颜色和大小 firework.style.left = Math.random() * 800 + 'px'; firework.style.top = '600px'; firework.style.backgroundColor = getRandomColor(); firework.style.width = Math.random() * 10 + 'px'; firework.style.height = Math.random() * 10 + 'px'; // 添加烟花到容器中 document.getElementById('fireworks-container').appendChild(firework); // 动画效果,逐渐增大烟花的大小并向上移动 firework.animate([ { transform: 'scale(1)', top: '600px' }, { transform: 'scale(5)', top: '0px' } ], { duration: 2000, easing: 'linear', fill: 'both' }); // 在烟花消失后移除烟花元素 firework.addEventListener('animationend', function() { this.parentNode.removeChild(this); }); } function getRandomColor() { var letters = '0123456789ABCDEF'; var color = '#'; for (var i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; } // 每隔一段时间创建一个新的烟花 setInterval(createFirework, 1000); ``` 通过以上的 HTML、CSS 和 JavaScript 代码,我们可以生成一个简单的页面,模拟放烟花的效果。这只是一个基础的示例,你可以根据需求进一步添加更多的粒子效果、不同的烟花爆炸动画等来增加页面的交互性和视觉效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值