jquery实现漂浮广告代码

jquery 实现漂浮广告代码

jquery 实现漂浮广告代码

要实现一个漂浮广告效果,可以使用 jQuery 中的animate()方法来实现元素的动画效果。以下是一个简单的示例代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Float Ad</title>
<style>
    #floatAd {
        position: fixed;
        bottom: 10px;
        right: 10px;
        width: 200px;
        height: 100px;
        background-color: #f00;
        color: #fff;
        text-align: center;
        line-height: 100px;
        display: none;
    }
</style>
</head>
<body>
<div id="floatAd">Floating Ad</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    $(document).ready(function() {
        $('#floatAd').fadeIn().animate({
            right: '50px',
            opacity: '0.7'
        }, 2000).animate({
            right: '10px',
            opacity: '1'
        }, 2000);
    });
</script>
</body>
</html>

在上面的示例中,我们在页面中创建了一个固定位置的浮动广告元素#floatAd,初始时设置为display: none隐藏。然后在 jQuery 的$(document).ready()方法中,使用fadeIn()方法使元素淡入显示,然后使用animate()方法实现元素向右移动和透明度改变的动画效果。

以上就是 jquery 实现漂浮广告代码的详细内容,更多请关注码云笔记其它相关文章!

「点点赞赏,手留余香」

0

给作者打赏,鼓励TA抓紧创作!

微信微信 支付宝支付宝

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系maynote@foxmail.com处理
码云笔记 » jquery实现漂浮广告代码

发表回复