Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converting alpinejs code to _hyperscript #526

Open
sqllyw opened this issue Mar 27, 2024 · 6 comments
Open

converting alpinejs code to _hyperscript #526

sqllyw opened this issue Mar 27, 2024 · 6 comments

Comments

@sqllyw
Copy link

sqllyw commented Mar 27, 2024

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/

@andryyy
Copy link

andryyy commented Mar 27, 2024

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.

@sqllyw
Copy link
Author

sqllyw commented Mar 27, 2024

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

@sqllyw
Copy link
Author

sqllyw commented Mar 27, 2024

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?

@andryyy
Copy link

andryyy commented Mar 27, 2024

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
Copy link

andryyy commented Mar 27, 2024

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.

@sqllyw
Copy link
Author

sqllyw commented Mar 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants