Skip to main content

svelte/reactivity/window

此模块导出了各种 window 值的响应式版本,每个值都有一个响应式的 current 属性,你可以在响应式上下文(模板、derivedseffects)中引用这些属性,而无需使用 <svelte:window> 绑定或手动创建自己的事件监听器。

<script>
	import { innerWidth, innerHeight } from 'svelte/reactivity/window';
</script>

<p>{innerWidth.current}x{innerHeight.current}</p>
import {
	
const devicePixelRatio: {
    readonly current: number | undefined;
}

devicePixelRatio.current is a reactive view of window.devicePixelRatio. On the server it is undefined. Note that behaviour differs between browsers — on Chrome it will respond to the current zoom level, on Firefox and Safari it won’t.

@since5.11.0
devicePixelRatio
,
const innerHeight: ReactiveValue<number | undefined>

innerHeight.current is a reactive view of window.innerHeight. On the server it is undefined.

@since5.11.0
innerHeight
,
const innerWidth: ReactiveValue<number | undefined>

innerWidth.current is a reactive view of window.innerWidth. On the server it is undefined.

@since5.11.0
innerWidth
,
const online: ReactiveValue<boolean | undefined>

online.current is a reactive view of navigator.onLine. On the server it is undefined.

@since5.11.0
online
,
const outerHeight: ReactiveValue<number | undefined>

outerHeight.current is a reactive view of window.outerHeight. On the server it is undefined.

@since5.11.0
outerHeight
,
const outerWidth: ReactiveValue<number | undefined>

outerWidth.current is a reactive view of window.outerWidth. On the server it is undefined.

@since5.11.0
outerWidth
,
const screenLeft: ReactiveValue<number | undefined>

screenLeft.current is a reactive view of window.screenLeft. It is updated inside a requestAnimationFrame callback. On the server it is undefined.

@since5.11.0
screenLeft
,
const screenTop: ReactiveValue<number | undefined>

screenTop.current is a reactive view of window.screenTop. It is updated inside a requestAnimationFrame callback. On the server it is undefined.

@since5.11.0
screenTop
,
const scrollX: ReactiveValue<number | undefined>

scrollX.current is a reactive view of window.scrollX. On the server it is undefined.

@since5.11.0
scrollX
,
const scrollY: ReactiveValue<number | undefined>

scrollY.current is a reactive view of window.scrollY. On the server it is undefined.

@since5.11.0
scrollY
} from 'svelte/reactivity/window';

devicePixelRatio

自 5.11.0 版本可用

devicePixelRatio.currentwindow.devicePixelRatio 的响应式视图。在服务端它是 undefined。注意不同浏览器的行为有所不同 — 在 Chrome 中它会响应当前缩放级别,在 Firefox 和 Safari 中则不会。

const devicePixelRatio: {
	get current(): number | undefined;
};

innerHeight

自 5.11.0 版本可用

innerHeight.currentwindow.innerHeight 的响应式视图。在服务端它是 undefined

const innerHeight: ReactiveValue<number | undefined>;

innerWidth

自 5.11.0 版本可用

innerWidth.currentwindow.innerWidth 的响应式视图。在服务端它是 undefined

const innerWidth: ReactiveValue<number | undefined>;

online

自 5.11.0 版本可用

online.currentnavigator.onLine 的响应式视图。在服务端它是 undefined

const online: ReactiveValue<boolean | undefined>;

outerHeight

自 5.11.0 版本可用

outerHeight.currentwindow.outerHeight 的响应式视图。在服务端它是 undefined

const outerHeight: ReactiveValue<number | undefined>;

outerWidth

自 5.11.0 版本可用

outerWidth.currentwindow.outerWidth 的响应式视图。在服务端它是 undefined

const outerWidth: ReactiveValue<number | undefined>;

screenLeft

自 5.11.0 版本可用

screenLeft.currentwindow.screenLeft 的响应式视图。它在 requestAnimationFrame 回调中更新。在服务端它是 undefined

const screenLeft: ReactiveValue<number | undefined>;

screenTop

自 5.11.0 版本可用

screenTop.currentwindow.screenTop 的响应式视图。它在 requestAnimationFrame 回调中更新。在服务端它是 undefined

const screenTop: ReactiveValue<number | undefined>;

scrollX

自 5.11.0 版本可用

scrollX.currentwindow.scrollX 的响应式视图。在服务端它是 undefined

const scrollX: ReactiveValue<number | undefined>;

scrollY

自 5.11.0 版本可用

scrollY.currentwindow.scrollY 的响应式视图。在服务端它是 undefined

const scrollY: ReactiveValue<number | undefined>;

在 GitHub 编辑此页面

上一页 下一页