固定底部悬浮在底部css效果顶部layui

css固定底部悬浮在底部顶部

<link href="//unpkg.com/layui@2.9.3/dist/css/layui.css" rel="stylesheet">

<div class="layui-btn-container" style="position:fixed; bottom: 10px; right: 10px;">
    <button type="button" class="layui-btn layui-bg-blue">蓝色按钮</button>
</div>

优化下代码,并附上JQUERY

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hello World</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="/assets/layui/css/layui111.css" rel="stylesheet">
    <script type="text/javascript" src="/assets/js/jquery.js"></script>

</head>
<body class="layui-padding-3">


<div class="layui-btn-container">
    <?php foreach($result as $row):?>
    <div class="products_lists" goods_attr_id="<?php echo $row['goods_attr_id'];?>">
        <div><img src="<?php echo $row['goods_image1'];?>" style="width:100px;height:100px;"></div>
        <div class="products_title"><?php echo $row['goods_name1'];?> <?php echo $row['goods_attr'];?></div>
    </div>
    <?php endforeach;?>
</div>


<div style="clear: both;"></div>


<div style="height: 30px;"></div>

<div style="position:fixed; bottom: 0px; right: 0px;text-align: center;padding:3px; background-color: #fff; width: 100%;">

<div class="layui-btn-container">
    <button type="button" class="layui-btn layui-bg-blue">下一步</button>
</div>
</div>
<style>
    .products_lists{display:block;height:160px; border:1px solid #F2F2F2; padding: 3px; float: left;margin: 5px; text-align: center;}
    .products_lists img{height:100px;}
    .products_title{max-width:100px;}
    .selected_div{background-color: #1e9fff; color: #ffffff;}
</style>

<script type="text/javascript">
    $(function (){
        id_lists = [];
        $(".products_lists").click(function () {
            goods_attr_id = $(this).attr("goods_attr_id");
            if ($(this).hasClass("selected_div")) {
                $(this).removeClass("selected_div");
                // 使用 jQuery.inArray 查找 ID 在数组中的索引
                var index = $.inArray(goods_attr_id, id_lists);
                if (index !== -1) {
                    id_lists.splice(index, 1);
                }
            } else {
                $(this).addClass("selected_div");
                id_lists.push(goods_attr_id);
            }
            console.log(id_lists);
        });

    });
</script>

</body>
</html>

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值