init
This commit is contained in:
172
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.js
vendored
Normal file
172
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.js
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const uni_modules_nutuiUni_components__constants_prefix = require("../_constants/prefix.js");
|
||||
const uni_modules_nutuiUni_components__hooks_useRect = require("../_hooks/useRect.js");
|
||||
const uni_modules_nutuiUni_components__utils_common = require("../_utils/common.js");
|
||||
const uni_modules_nutuiUni_components__utils_env = require("../_utils/env.js");
|
||||
const uni_modules_nutuiUni_components__utils_pxCheck = require("../_utils/pxCheck.js");
|
||||
const uni_modules_nutuiUni_components__utils_style = require("../_utils/style.js");
|
||||
const uni_modules_nutuiUni_components__utils_props = require("../_utils/props.js");
|
||||
const stickyProps = {
|
||||
...uni_modules_nutuiUni_components__utils_props.commonProps,
|
||||
/**
|
||||
* @description 吸顶距离
|
||||
*/
|
||||
offsetTop: uni_modules_nutuiUni_components__utils_props.makeNumericProp(0),
|
||||
/**
|
||||
* @description 吸附时的层级
|
||||
*/
|
||||
zIndex: {
|
||||
type: [Number, String],
|
||||
default: 2e3
|
||||
},
|
||||
/**
|
||||
* @description 导航栏高度,自定义导航栏时,需要传入此值
|
||||
* - H5端的导航栏属于“自定义”导航栏的范畴,因为它是非原生的,与普通元素一致
|
||||
*/
|
||||
customNavHeight: uni_modules_nutuiUni_components__utils_props.makeNumericProp(uni_modules_nutuiUni_components__utils_env.isH5 ? 44 : 0),
|
||||
/**
|
||||
* @description 是否开启吸顶功能
|
||||
*/
|
||||
disabled: Boolean,
|
||||
/**
|
||||
* @description 吸顶区域的背景颜色
|
||||
*/
|
||||
bgColor: uni_modules_nutuiUni_components__utils_props.makeStringProp("transparent")
|
||||
};
|
||||
const componentName = `${uni_modules_nutuiUni_components__constants_prefix.PREFIX}-sticky`;
|
||||
const __default__ = common_vendor.defineComponent({
|
||||
name: componentName,
|
||||
options: {
|
||||
virtualHost: true,
|
||||
addGlobalClass: true,
|
||||
styleIsolation: "shared"
|
||||
}
|
||||
});
|
||||
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
...__default__,
|
||||
props: stickyProps,
|
||||
setup(__props) {
|
||||
const props = __props;
|
||||
const instance = common_vendor.getCurrentInstance();
|
||||
const elementId = `${componentName}-${uni_modules_nutuiUni_components__utils_common.getRandomId()}`;
|
||||
const cssSticky = common_vendor.ref(false);
|
||||
const left = common_vendor.ref(0);
|
||||
const width = common_vendor.ref("auto");
|
||||
const height = common_vendor.ref("auto");
|
||||
const fixed = common_vendor.ref(false);
|
||||
const classes = common_vendor.computed(() => {
|
||||
return uni_modules_nutuiUni_components__utils_style.getMainClass(props, componentName);
|
||||
});
|
||||
const stickyTop = common_vendor.computed(() => {
|
||||
return Number(uni_modules_nutuiUni_components__utils_style.getPx(props.offsetTop)) + Number(uni_modules_nutuiUni_components__utils_style.getPx(props.customNavHeight));
|
||||
});
|
||||
const styles = common_vendor.computed(() => {
|
||||
const value = {};
|
||||
if (!props.disabled) {
|
||||
if (cssSticky.value) {
|
||||
value.position = "sticky";
|
||||
value.top = uni_modules_nutuiUni_components__utils_pxCheck.pxCheck(stickyTop.value);
|
||||
value.zIndex = props.zIndex;
|
||||
} else {
|
||||
if (!fixed.value || height.value === "auto") {
|
||||
value.height = "auto";
|
||||
} else {
|
||||
value.height = `${height.value}px`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value.position = "static";
|
||||
}
|
||||
value.backgroundColor = props.bgColor;
|
||||
return uni_modules_nutuiUni_components__utils_style.getMainStyle(props, value);
|
||||
});
|
||||
const contentStyles = common_vendor.computed(() => {
|
||||
const value = {};
|
||||
if (!cssSticky.value) {
|
||||
value.position = fixed.value ? "fixed" : "static";
|
||||
value.top = `${stickyTop.value}px`;
|
||||
value.left = `${left.value}px`;
|
||||
value.width = width.value === "auto" ? "auto" : `${width.value}px`;
|
||||
value.zIndex = props.zIndex;
|
||||
}
|
||||
return value;
|
||||
});
|
||||
function setFixed(top) {
|
||||
fixed.value = top <= stickyTop.value;
|
||||
}
|
||||
const observer = common_vendor.shallowRef(null);
|
||||
function disconnectObserver() {
|
||||
if (observer.value == null)
|
||||
return;
|
||||
observer.value.disconnect();
|
||||
observer.value = null;
|
||||
}
|
||||
function observeContent() {
|
||||
disconnectObserver();
|
||||
const contentObserver = common_vendor.index.createIntersectionObserver({
|
||||
// 检测的区间范围
|
||||
thresholds: [0.95, 0.98, 1]
|
||||
});
|
||||
contentObserver.relativeToViewport({
|
||||
top: -stickyTop.value
|
||||
});
|
||||
contentObserver.observe(`#${elementId}`, (res) => {
|
||||
setFixed(res.boundingClientRect.top);
|
||||
});
|
||||
observer.value = contentObserver;
|
||||
}
|
||||
function initObserveContent() {
|
||||
uni_modules_nutuiUni_components__hooks_useRect.useRect(elementId, instance).then((res) => {
|
||||
left.value = res.left;
|
||||
width.value = String(res.width);
|
||||
height.value = String(res.height);
|
||||
common_vendor.nextTick$1(() => {
|
||||
observeContent();
|
||||
});
|
||||
});
|
||||
}
|
||||
function checkComputedStyle() {
|
||||
return new Promise((resolve) => {
|
||||
common_vendor.index.createSelectorQuery().in(instance).select(`.${componentName}`).fields({
|
||||
computedStyle: ["position"]
|
||||
}, () => {
|
||||
}).exec((res) => {
|
||||
resolve(res[0].position === "sticky");
|
||||
});
|
||||
});
|
||||
}
|
||||
async function checkSupportCssSticky() {
|
||||
const systemInfo = common_vendor.index.getSystemInfoSync();
|
||||
if (systemInfo.osName === "android" && Number.parseInt(systemInfo.osVersion) > 8)
|
||||
cssSticky.value = true;
|
||||
cssSticky.value = await checkComputedStyle();
|
||||
if (systemInfo.osName === "ios")
|
||||
cssSticky.value = true;
|
||||
}
|
||||
function init() {
|
||||
checkSupportCssSticky();
|
||||
if (!cssSticky.value) {
|
||||
if (!props.disabled) {
|
||||
initObserveContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
common_vendor.onMounted(() => {
|
||||
init();
|
||||
});
|
||||
common_vendor.onUnmounted(() => {
|
||||
disconnectObserver();
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
return {
|
||||
a: common_vendor.s(contentStyles.value),
|
||||
b: elementId,
|
||||
c: common_vendor.n(classes.value),
|
||||
d: common_vendor.s(styles.value)
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
wx.createComponent(_sfc_main);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.js.map
|
||||
4
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.json
vendored
Normal file
4
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
1
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.wxml
vendored
Normal file
1
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.wxml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<view id="{{b}}" class="{{c}}" style="{{d}}"><view class="nut-sticky__content" style="{{a}}"><slot/></view></view>
|
||||
54
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.wxss
vendored
Normal file
54
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/sticky/sticky.wxss
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.nut-sticky {
|
||||
position: -webkit-sticky;
|
||||
position: sticky;
|
||||
}
|
||||
Reference in New Issue
Block a user