diff --git a/example/src/index.html b/example/src/index.html
index abdaaff..ee15b16 100644
--- a/example/src/index.html
+++ b/example/src/index.html
@@ -104,6 +104,11 @@
(code)
+
+ z-index offset
+
+ (code)
+
View on Github
diff --git a/example/src/main.ts b/example/src/main.ts
index 714be18..794c876 100644
--- a/example/src/main.ts
+++ b/example/src/main.ts
@@ -8,6 +8,7 @@ import Sample5 from "./sample5.vue"
import Sample6 from "./sample6.vue"
import Sample7 from "./sample7.vue"
import Sample8 from "./sample8.vue"
+import Sample9 from "./sample9.vue"
Vue.use(VueWindow)
@@ -23,6 +24,7 @@ window.addEventListener('load', e => {
Sample6,
Sample7,
Sample8,
+ Sample9,
} as any)[location.search.substr(1)] || Sample1
new Vue({
el: emptyElement(),
diff --git a/example/src/sample9.vue b/example/src/sample9.vue
new file mode 100644
index 0000000..fbfc0fc
--- /dev/null
+++ b/example/src/sample9.vue
@@ -0,0 +1,55 @@
+
+
+
\ No newline at end of file
diff --git a/src/window/script.ts b/src/window/script.ts
index 11cb06e..7dbf26c 100644
--- a/src/window/script.ts
+++ b/src/window/script.ts
@@ -49,6 +49,9 @@ export class WindowType extends Vue {
@Prop({ type: Number, default: 0 })
zGroup!: number
+ @Prop({ type: Number, default: 0 })
+ zOffset?: number
+
@Prop({ default: 'visible' })
overflow!: string
@@ -64,7 +67,7 @@ export class WindowType extends Vue {
mounted() {
instances.push(this)
- this.zElement = new ZElement(this.zGroup, zIndex => this.zIndex = `${zIndex}`)
+ this.zElement = new ZElement(this.zGroup, zIndex => this.zIndex = `${zIndex}`, this.zOffset)
this.isOpen && this.onIsOpenChange(true)
windows.add(this)
}
diff --git a/src/z_element.ts b/src/z_element.ts
index 39547f3..359e0fd 100644
--- a/src/z_element.ts
+++ b/src/z_element.ts
@@ -1,7 +1,7 @@
export class ZElement {
zIndex?: number
- constructor(private _group: number, public onChange: (zIndex: number) => void) {
+ constructor(private _group: number, public onChange: (zIndex: number) => void, private _offset: number = 0) {
this.a(a => a.push(this))
}
@@ -17,6 +17,10 @@ export class ZElement {
get group() {
return this._group
}
+
+ get zIndexOffset(): number {
+ return this._offset
+ }
unregister() {
this.a(a => a.splice(a.indexOf(this), 1))
@@ -66,15 +70,18 @@ function compare(a: number, b: number): number {
function refresh() {
- let zIndex = BASE
+ let zIndex: number = BASE
for (const g of keys(registry).sort(compare)) {
- for (const z of a(g)) {
- if (zIndex != z.zIndex) {
- z.zIndex = zIndex
- z.onChange(zIndex)
+ const groups: ZElement[] = a(g)
+ let groupIndex: number = (groups[0] && groups[0].zIndexOffset) ? Number(groups[0].zIndexOffset) : zIndex
+ for (const z of groups) {
+ if (groupIndex != z.zIndex) {
+ z.zIndex = groupIndex
+ z.onChange(groupIndex)
}
- zIndex++
+ groupIndex++
}
+ zIndex += groups.length
}
}