jQuery实现对联式广告

本文介绍了一种基于页面滚动距离的广告位显示与隐藏策略,利用jQuery监听屏幕滚动事件,实现广告位的动态调整,增强用户体验的同时提高广告效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>advertising</title>
    <link rel="icon" href="../../../img/sup.ico" type="img/x-icon">
    <script src="../../../jquery-3.4.1.min.js"></script>
    <style type="text/css">
        body{
            height: 3000px;
        }
        div:first-child{
            background-color: #ccc;
            position: fixed;
            top: 350px;
            float: left;
            left: 0;

            font-size: 0;
            color: #f4511e;
            text-align: center;
            line-height: 200px;
            writing-mode: vertical-lr;
        }
        div:nth-child(2){
            background-color: #ccc;
            position: fixed;
            top: 350px;
            float: right;
            right: 0;
            font-size: 0;

            color: #f4511e;
            text-align: center;
            line-height: 200px;
            writing-mode: vertical-lr;
        }
    </style>
</head>
<body>
    <div>广告位火热招商中</div>
    <div>广告位火热招商中</div>
<script>
    //监听屏幕滚动距离
    $(function () {
        $(window).on('scroll',function () {//事件添加在window上
            let $scrollTop = $('html,body').scrollTop();
            console.log($scrollTop);
            if ($scrollTop < 500){
                $('div').hide().animate({
                    width:0,
                    height:0,
                    fontSize:'0px',
                },100);
            }else{
                $('div').show().animate({
                    width:200,
                    height:400,
                    fontSize:'40px',
                },500)
            }
        })
    })
</script>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值