H5页面悬浮球,可拖动

H5页面悬浮球,可拖动

$(document).ready(function() {
	//设置样式
	$("body").css({"margin":0,"padding":0});
	$(".homepage-btn").css({//初始化HOME图标到屏幕右上角
		"left":($(window).width()-$(".homepage-btn").width()-10) + "px"	,			
		"top":"85%"		
	})
	setTimeout('$(".homepage-btn").css({"opacity":"0.2","-webkit-transition":"opacity 2s"})',3000);
    //绑定home键事件
	$(".homepage-btn").click(function() {
		window.location.href = getLocalStorageValue("homeUrl");
	});
	//home键在屏幕移动
	var cont=$(".homepage-btn");	
	var contW=cont.width();
	var contH=cont.height();			
	var startX,startY,sX,sY,moveX,moveY;		
	var winW=$(window).width();	
	var winH=$(window).height();
	var barrage_name=$(".homepage-btn").children(".home");
	var body=$("body");
	
	cont.on({//绑定事件
		touchstart:function(e){
			$(".homepage-btn").css({"opacity":"0.9","-webkit-transition":"opacity 0.1s"});
			//$(".homepage-btn").css({"animation":"fade-in","animation-duration":"0.5s","-webkit-animation":"fade-in 0.5s"});
			startX = e.originalEvent.targetTouches[0].pageX;	//获取点击点的X坐标	
			startY = e.originalEvent.targetTouches[0].pageY;    //获取点击点的Y坐标
			//console.log("startX="+startX+"************startY="+startY);
			sX=$(this).offset().left;//相对于当前窗口X轴的偏移量
			sY=$(this).offset().top;//相对于当前窗口Y轴的偏移量
			//console.log("sX="+sX+"***************sY="+sY);
			leftX=startX-sX;//鼠标所能移动的最左端是当前鼠标距div左边距的位置
			rightX=winW-contW+leftX-3;//鼠标所能移动的最右端是当前窗口距离减去鼠标距div最右端位置
			topY=startY-sY;//鼠标所能移动最上端是当前鼠标距div上边距的位置
			bottomY=winH-contH+topY-2;//鼠标所能移动最下端是当前窗口距离减去鼠标距div最下端位置				
			},
		touchmove:function(e){			
			e.preventDefault();
			moveX=e.originalEvent.targetTouches[0].pageX;//移动过程中X轴的坐标
			moveY=e.originalEvent.targetTouches[0].pageY;//移动过程中Y轴的坐标
			//console.log("moveX="+moveX+"************moveY="+moveY);
			if(moveX<leftX){moveX=leftX;}								
			if(moveX>rightX){moveX=rightX;}
			if(moveY<topY){moveY=topY;}
			if(moveY>bottomY){moveY=bottomY;}			
			$(this).css({
				"left":moveX+sX-startX,
				"top":moveY+sY-startY
			})
			/*setLocalStorageValue("home_left",moveX+sX-startX);
			setLocalStorageValue("home_top",moveY+sY-startY);*/
			},
		touchend:function(e){
			var curX = moveX+sX-startX;//当前拖动位置的X坐标
			var curY = moveY+sY-startY;//当前拖动位置的Y坐标
			/**
			 * 如果当前拖动位置X坐标等于0或者Y坐标等于0,则按照拖动的坐标定位。否则,按重新定位
			 */ 
			 if(curX && curY){
			 	if((curX == 0  || curX+44+3 == $(window).width()) || curY == 0  || curY+44+2 == $(window).height()){
				}else{
					if(curX >= $(window).width()/2){
						curX = ($(window).width()-$(".homepage-btn").width()-3);
					}else{
						curX = 3;
					}
				}
				$(this).css({
					"left":curX + "px"	,
					"top":curY + "px"	
				});
			 }
			 setTimeout('$(".homepage-btn").css({"opacity":"0.2","-webkit-transition":"opacity 2s"})',3000);
		},
	})
	
	
	//公共图片查看大图方法
	
	$("body").delegate('#imageCKDT','click',ckdt);
	
	
});
/**获取文件绝对路径前缀**/
function basePath() {
	//当前页面的绝对路径
	var curWwwPath = window.document.location.href;
	//当前页面的相对路径
	var pathName = window.document.location.pathname;
	//获取相对路径在绝对路径中的位置
	var pos = curWwwPath.indexOf(pathName);
	//获取路径前缀
	var localhostPath = curWwwPath.substring(0, pos);
	//获取项目名称
	var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
	return localhostPath + projectName;
}



function ckdt(){
		if($("#model").length==0){
			$(document.body).append('<div id="model" style="position: fixed;top: 0;right: 0;bottom: 0;left: 0;overflow: hidden;outline: 0;-webkit-overflow-scrolling: touch; background-color: rgb(0, 0, 0);  filter: alpha(opacity=60); background-color: rgba(0, 0, 0, 0.6); z-index: 300005;display:none;" onclick="javascript:$(\'#model\').hide();"></div>');
		};
		var Height=document.body.clientHeight;//取得页面可视区域的高度
		var Width=document.body.clientWidth;//取得页面可视区域的宽度
		$("#model").show();
		var html = '<div class="first" style="text-align:center;"></div>';
		$("#model").html(html);
		//$('#PhotoDiv').find('img').attr('src');
		$("#model").children("div[class='first']").css({"width":Width,"height":Width,"top":(Height-Width)/2,"left":"0","position":"absolute","z-index":"100005"});
		var img = '<img id="imgDiv"  src="'+$(this).attr("src")+'" style="max-height:'+Width+',max-width:'+Width+';z-index:100005;padding:0;"></img>';
		$("#model").children("div[class='first']").html(img);
		//设置图片大小 
		if($("#imgDiv").height() >= Width){
	    	$("#imgDiv").css("height",Width);
	    }
	    if($("#imgDiv").width() >= Width){
	    	$("#imgDiv").css("width",Width);
	    }
		//让图片原始大小展示 于屏幕中央
		var DivHeight = document.getElementById("imgDiv").offsetHeight;//获取div块的高度值
		var DivWidth = document.getElementById("imgDiv").offsetWidth;//获取div块中文字所在span的宽度值 
	    var left = (Width - DivWidth) / 2  +  "px";//距容器左边的距离  
	    var top = ($("#model").children("div[class='first']").height() - DivHeight) / 2  +  "px";//距容器上方的距离  
	    $("#imgDiv").css({'position':'absolute','top':top,'z-index':'100005','left':left});
}

css文件

.homepage-btn {
			position: fixed;
			/*right: 10px;*/
			left:200px;
			top: 10px;
			width: 46px;
			height: 46px;
			/**-webkit-transition:opacity 2s;规定完成过渡效果需要2秒*/
			opacity: 0.9;
			/*background:rgba(101,211,186,0.70);*/
			background:-webkit-gradient(linear,0 0,100% 100%,from(#fff), to(#4B98F0));
			/* border:1px solid rgba(75,152,240,0.5); */
			box-shadow:0 2px 4px 0 rgba(110,103,103,0.50);
			border-radius:100%;
			display:block;
			z-index:999;
		}
		.homepage-btn .icon {
			display: inline-block;
			width: 100%;
			height: 100%;
			background: url(../../image/icon-add.png) no-repeat center center/70%;
		}

页面使用:在body中加入

<div class="homepage-btn">
		<i class="icon home"></i>
	</div>

 

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您可以使用Ant Design Vue和Vue-Grid-Layout来实现一个可编辑的H5页面生成器。 Ant Design Vue是一套基于Vue.js的UI组件库,提供了丰富的组件和样式,可以帮助您快速搭建页面。 Vue-Grid-Layout是一个基于Vue.js的栅格布局组件,可以让您轻松地实现可拖拽和可调整大小的网格布局。 您可以使用Ant Design Vue来设计页面组件和样式,然后使用Vue-Grid-Layout来实现可编辑的网格布局。用户可以通过拖拽和调整大小来修改页面布局,最终生成H5页面。 下面是一个简单的示例代码: ```vue <template> <div> <vue-grid-layout :layout.sync="layout" :col-num="12" :row-height="30" :is-draggable="true" :is-resizable="true"> <div v-for="item in layout" :key="item.i" :data-grid="item"> <div :class="item.class"> {{item.i}} </div> </div> </vue-grid-layout> </div> </template> <script> import VueGridLayout from 'vue-grid-layout'; import { Button } from 'ant-design-vue'; export default { components: { VueGridLayout, Button, }, data() { return { layout: [ { i: 'a', x: 0, y: 0, w: 6, h: 4, class: 'box' }, { i: 'b', x: 6, y: 0, w: 6, h: 4, class: 'box' }, { i: 'c', x: 0, y: 4, w: 12, h: 4, class: 'box' }, ], }; }, }; </script> <style> .box { background-color: #eee; border: 1px solid #ccc; border-radius: 4px; display: flex; justify-content: center; align-items: center; } </style> ``` 在这个示例中,我们使用了Ant Design Vue的Button组件来作为页面上的一个组件,并使用Vue-Grid-Layout来实现可编辑的网格布局。 您可以根据您的需求进行定制和扩展,实现一个符合您需求的可编辑的H5页面生成器。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

残月飞鹰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值