修复取色框点击位置错乱问题

This commit is contained in:
KeiferJu 2020-06-11 11:29:19 +08:00
parent 6bbebb0160
commit cdefea265c
2 changed files with 17 additions and 9 deletions

View File

@ -2,7 +2,7 @@
"name": "svelma-pro",
"svelte": "src/index.js",
"description": "Based on svelma project extension and modification",
"version": "1.2.1",
"version": "1.2.2",
"author": "KeiferJu",
"license": "MIT",
"keywords": [

View File

@ -19,13 +19,14 @@
let focusStatus = false
function openChrome(event) {
focusStatus = true
panelX = event.clientX - event.offsetX
panelY = event.clientY
transformX = event.target.offsetWidth + 5
console.log(event)
if (!active) {
panelX = event.clientX - event.offsetX
panelY = event.clientY
transformX = event.target.offsetWidth + 5
setTimeout(()=>{
setTimeout(() => {
active = true
},100)
}, 100)
}
}
@ -65,16 +66,23 @@
<svelte:window on:click={closeChrome} />
{#if mode === 1}
<div class="smx-color-picker" style="width: {width}">
<input type="text" class="input" on:focus={openChrome} on:blur={()=>focusStatus = false} value={color} style="background: {color};" readonly />
<input
type="text"
class="input"
on:click={openChrome}
on:blur={() => (focusStatus = false)}
value={color}
style="background: {color};"
readonly />
{#if active}
<div
class="smx-color-panel"
on:click|stopPropagation
style="top: {panelY}px;left:{panelX}px;transform: translate({transformX}px, -50%)">
<Chrome startColor={color} on:input={handleInput} {fieldsIndex} on:mouseupEvent={mouseupEvent}/>
<Chrome startColor={color} on:input={handleInput} {fieldsIndex} on:mouseupEvent={mouseupEvent} />
</div>
{/if}
</div>
{:else}
<Chrome startColor={color} on:input={handleInput} {fieldsIndex} on:mouseupEvent={mouseupEvent}/>
<Chrome startColor={color} on:input={handleInput} {fieldsIndex} on:mouseupEvent={mouseupEvent} />
{/if}