HTML页面悬浮球,html滑动仿悬浮球菜单

//声明属性赋值

var flag=0;

var motion = document.getElementById('xuanfu');

var disX,disY; //元素左/上 ‘半径’

var moveX,moveY;

var L,T; //可移动范围

var starX,starY;

var starXEnd,starYEnd;

//监听移动开始

motion.addEventListener('touchstart',touchstartFun);

function touchstartFun(e){

flag = 0;

e.preventDefault(); //阻止触摸按钮时页面滚动和缩放

//获取元素左/上边到中心(clientX,clientY)的距离

disX = e.touches[0].clientX - this.offsetLeft;

disY = e.touches[0].clientY - this.offsetTop;

//手指按下屏幕时的坐标

starX = e.touches[0].clientX;

starY = e.touches[0].clientY;

motion.addEventListener('touchend',touchendFun);//监听点击

}

//监听移动事件

motion.addEventListener('touchmove',function(e){

motion.removeEventListener('touchend',touchendFun);//删除监听点击事件

flag = 1;

L = e.touches[0].clientX - disX ;

T = e.touches[0].clientY - disY ;

//移动时当前位置和起始位置的差值

starXEnd = e.touches[0].clientX - starX;

starYEnd = e.touches[0].clientY - starY;

if(L<0){

L = 0; //限制拖拽的X范围,不能拖出屏幕

}else if(L > document.documentElement.clientWidth - this.offsetWidth){

L=doc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现一个悬浮,可以使用HTML和CSS中的position属性和z-index属性。 以下是一个简单的示例代码: ```html <div class="float-module"> <div class="float-ball"></div> <div class="float-content"> <!-- 这里可以放置悬浮的内容 --> </div> </div> ``` ```css .float-module { position: fixed; bottom: 20px; right: 20px; z-index: 9999; } .float-ball { width: 50px; height: 50px; border-radius: 50%; background-color: red; cursor: pointer; } .float-content { position: absolute; bottom: 70px; right: -10px; width: 200px; height: 200px; padding: 10px; background-color: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); display: none; } .float-ball:hover + .float-content, .float-content:hover { display: block; } ``` 在上面的代码中,使用了position: fixed属性将整个悬浮模块固定在浏览器窗口的右下角。z-index属性用于确保该元素始终在其他元素上方。 悬浮的样式使用了width、height、border-radius和background-color等属性来实现。cursor: pointer属性可以让鼠标在悬浮上移动时变成手型。 悬浮内容的样式使用了position: absolute属性将其定位到悬浮的下方,并使用了bottom和right属性来微调其位置。width和height属性用于设置悬浮内容的大小。padding属性用于设置内容与边框的间距。background-color和box-shadow属性用于设置内容的背景和阴影。 最后,使用:hover伪类和+选择器来实现鼠标悬停在悬浮上时显示悬浮内容的效果。当鼠标移开悬浮悬浮内容时,悬浮内容会消失。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值