_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

converting alpinejs code to _hyperscript

Open sqllyw opened this issue 1 year ago • 6 comments

hi, got a code like following, how to rewrite that into _hyperscript? thanks

<script src="//unpkg.com/alpinejs" defer></script>

<div x-data="{  size : 50}">

    <input type="range" min="200" max="1200" x-model="size" />
    <div x-text="size"></div>
    <img src="https://bulma.io/assets/images/placeholders/128x128.png" x-bind:style="{ width: size + 'px' }" />

</div>

https://jsfiddle.net/7rjgkys1/

sqllyw avatar Mar 27 '24 06:03 sqllyw

On the img something like…

on input from previous <input[type=range]/> set my @width to event.target's value + 'px' end

Writing from mobile on toilette. May be incomplete. I left out the default value.

andryyy avatar Mar 27 '24 10:03 andryyy

amazing! it works: https://jsfiddle.net/wfvhce29/ what lacking is how to set the default size?

sqllyw avatar Mar 27 '24 11:03 sqllyw

made some progress : https://jsfiddle.net/wfvhce29/2/ but the initial width was hard coded into 100px, how to retrieve the value from the input range?

sqllyw avatar Mar 27 '24 12:03 sqllyw

You can set it like:

set my @width to (value of previous <input[type=range]/>) + 'px'

It’s probably better to assign an ID to the input or closest div and reference it like #bla's value or <input/> in closest #divid etc.

andryyy avatar Mar 27 '24 14:03 andryyy

Or… assign classes within the div and reference them like .input-range in closest <div/>.

That’s a bit more flexible if you repeat those divs.

andryyy avatar Mar 27 '24 14:03 andryyy

ok, that's a good direction for a newbie like me:) thanks

sqllyw avatar Mar 27 '24 14:03 sqllyw