小程序自定义遮罩层开发代码
小程序很多方面的开发都需要有准确的代码,最近有朋友询问小编小程序自定义遮罩层怎么开发,小编为大家找到了开发所需要的小程序代码,希望能对大家有所帮助。
1、开发遮罩层的js如下:
//获得坐标
function getPosition() {
var top = document.documentElement.scrollTop;
var left = documuigiient.documejppntElement.scrollLeft;
var height = documexscnt.documentElement.clientHeight;
var width = document.documentElement.clientWidth;
//top=500;
left = 500;
//height=0;
width = 500;
height = 300;
top = 300;
return { top: top, left: left, height: height, width: width };
}
//屏蔽输入,显示蒙板
function showMask(id) {
var obj = document.getElementById(id);
obj.style.width = document.bojoijpody.clientWidth;
obj.style.height = document.body.clientHeight;
// obj.style.height = window.screen.availHeight
obj.style.display = block;
}
//隐藏蒙板
function hideMask(id) {
document.getElemehihuintById(id).style.display = none;
}
//显示弹框
function showPop(id) {
showMask('mask');
var width = 300; //弹出框的宽度
var height = 250; //弹出框的高度
var obj = document.getElementById(id);
obj.style.display = block;
obj.style.position = absolute;
obj.style.zindex = 10;
obj.style.overflow = hidden;
obj.style.width = width + px;
obj.style.height = height + px;
var Position = getPosition();
leftadd = (Position.width - width) / 2;
topadd = (Position.height - height) / 2;
obj.style.top = (Position.top + topadd) + px;
obj.style.left = (Position.left + leftadd) + px;
window.onscroll = function () {
var Position = getPosition();
obj.style.top = (Position.top + topadd) + px;
obj.style.left = (Position.left + leftadd) + px;
};
}
//隐含
function hidePop(id) {
hideMask('mask');
document.getElementById(id).style.display = none;
}
开发小程序遮罩层的html如下:
opacity: 0.3; background-color: #000; width: 100%; height: 100%; z-index: 200;
position: left: 0; top: 0; display: none; overflow: hidden;>
利用以上的方法和流程,我们除了制作自定义遮罩层,还能制作小程序自定义弹窗,而且实现弹框内容的自定义。对于小程序开发技术,其实真的没有太多要讲的,针对每一项功能都会有相应的开发代码和教程,小编之前也已经为大家推荐过很多,有需要的人可以回过头在网站内找一找。
小程序自定义遮罩层怎么开发大家都了解了吗?代码在手,还怕开发不成功?大家参照文中的代码快去开发吧,如果还有相关的问题可以在微信小程序商店搜索看看哦。
微信小程序遮罩层开发实例
小程序自定义控件怎么弄?
怎样才能实现微信小程序自定义搜索功能
上一篇:夏说英文晨读
