H5右侧悬浮

本文介绍了如何在H5中实现右侧悬浮效果,并且详细讲述了点击展开、收回及移除的功能。通过html和css代码片段,展示了具体的实现步骤,强调了在布局时使用绝对定位和margin的重要性。
前言:实现H5右侧悬浮,点击展开收回移除;

示例如下 ↓

默认:

在这里插入图片描述

点击动画移入:

在这里插入图片描述

html代码片段:
 <div class="right_item_menu">   
  <i class="right_menu_icon"></i>
    <div class="right_item" style="display: none;">
        <span class="right_item_title">今日XXX</span> 
        <div class="right_content">
        	   <img src="../pic.png" alt="">
             <p></p>
        </div>
        <i class="right_close_btn"></i>
    </div>
</div>
css代码片段:
.right_menu_icon{width:1rem;height:0.68rem;background: url(../images/right_icon.png);background-size: 100%;display: inline-block;position: absolute;top: -0.18rem;left:0rem;}
.right_item_menu{position: fixed;margin-left: 6.6rem;top:40%;color:#333;border-radius: 20px;padding-left:0.62rem;width: 5.8rem;z-index: 999;font-size:0.28rem;}
.right_item{background-color: #fff;color:#333;display: inline-block;border-radius: 5px;position: relative;width:100%;box-shadow: 5px 2px 8px 0px #e6e1e1;display: flex;align-items: center;}
.right_item_title{display: inline-block;}
.right_content{display: inline-block;width:2.8rem;height:0.5rem;display: flex;align-items: center;}
.right_close_btn{position: absolute;width: 0.3rem;height: 0.3rem;right: 0.05rem;top: 0.1rem;background: url(../images/delt.svg) no-repeat;background-size: 100%;border-radius: 100%;}
.right_content img{width:0.6rem;height:0.6rem;box-sizing: border-box;padding:0.02rem;border-radius: 100%;display: inline-block;align-items: baseline;}
.right_content p{white-space: normal;text-overflow: ellipsis;overflow: hidden;width: 2rem;height: 100%;line-height: 0.52rem;}

代码如下 ↓
注意:右侧悬浮绝对定位用margin是相对于body ;

$(".right_item_menu").click(function(){
    if($(this).hasClass('move_left')){
        $(this).find('.right_item').hide();
        $(this).animate({'margin-left':'6.6rem'},"slow").removeClass('move_left');
    }else{
        $(this).animate({'margin-left':'1.6rem'},"slow").addClass('move_left');
        $(this).find('.right_item').show();
    }
});
//关闭移除
$(".right_close_btn").click(function(){
    $(this).parents('.right_item_menu').hide();
});
//移动端适配:
(function(doc, win) {

    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            if (clientWidth >= 750) {
                // 这里的640 取决于设计稿的宽度
                docEl.style.fontSize = '100px';
            } else {
                docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
            }
        };

    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);

})(document, window);
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值