diff --git a/src/components/ReCountTo/README.md b/src/components/ReCountTo/README.md new file mode 100644 index 000000000..3656dbbeb --- /dev/null +++ b/src/components/ReCountTo/README.md @@ -0,0 +1,2 @@ +normal 普通数字动画组件 +rebound 回弹式数字动画组件 diff --git a/src/components/ReCountTo/index.ts b/src/components/ReCountTo/index.ts index d29729f86..bbd6266bd 100644 --- a/src/components/ReCountTo/index.ts +++ b/src/components/ReCountTo/index.ts @@ -1,10 +1,15 @@ import { App } from "vue"; -import reCountTo from "./src"; +import reNormalCountTo from "./src/normal"; +import reboundCountTo from "./src/rebound"; -export const ReCountTo = Object.assign(reCountTo, { +export const ReNormalCountTo = Object.assign(reNormalCountTo, { install(app: App) { - app.component(reCountTo.name, reCountTo); + app.component(reNormalCountTo.name, reNormalCountTo); } }); -export default ReCountTo; +export const ReboundCountTo = Object.assign(reboundCountTo, { + install(app: App) { + app.component(reboundCountTo.name, reboundCountTo); + } +}); diff --git a/src/components/ReCountTo/src/index.tsx b/src/components/ReCountTo/src/normal/index.tsx similarity index 99% rename from src/components/ReCountTo/src/index.tsx rename to src/components/ReCountTo/src/normal/index.tsx index 838192b0f..62e8d1926 100644 --- a/src/components/ReCountTo/src/index.tsx +++ b/src/components/ReCountTo/src/normal/index.tsx @@ -10,7 +10,7 @@ import { countToProps } from "./props"; import { isNumber } from "/@/utils/is"; export default defineComponent({ - name: "CountTo", + name: "Normal", props: countToProps, emits: ["mounted", "callback"], setup(props, { emit }) { diff --git a/src/components/ReCountTo/src/props.ts b/src/components/ReCountTo/src/normal/props.ts similarity index 100% rename from src/components/ReCountTo/src/props.ts rename to src/components/ReCountTo/src/normal/props.ts diff --git a/src/components/ReCountTo/src/rebound/index.tsx b/src/components/ReCountTo/src/rebound/index.tsx new file mode 100644 index 000000000..194df0a86 --- /dev/null +++ b/src/components/ReCountTo/src/rebound/index.tsx @@ -0,0 +1,73 @@ +import "./rebound.css"; +import { + defineComponent, + ref, + unref, + onBeforeMount, + onBeforeUnmount, + getCurrentInstance +} from "vue"; +import { reboundProps } from "./props"; + +export default defineComponent({ + name: "Rebound", + props: reboundProps, + setup(props) { + const timer = ref(null); + + onBeforeMount(() => { + const ua = navigator.userAgent.toLowerCase(); + const testUA = regexp => regexp.test(ua); + const isSafari = testUA(/safari/g) && !testUA(/chrome/g); + + // Safari浏览器的兼容代码 + isSafari && + (timer.value = setTimeout(() => { + // @ts-ignore + getCurrentInstance().refs["ul"].setAttribute( + "style", + ` + animation: none; + transform: translateY(calc(var(--i) * -9.09%)) + ` + ); + }, props.delay * 1000)); + }); + + onBeforeUnmount(() => { + clearTimeout(unref(timer)); + }); + + return () => ( + <> +