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

document.documentElement.style.setProperty #1192

Closed
rajeevnttdata opened this issue Sep 22, 2023 · 4 comments
Closed

document.documentElement.style.setProperty #1192

rajeevnttdata opened this issue Sep 22, 2023 · 4 comments

Comments

@rajeevnttdata
Copy link

How to achieve functionality for document.documentElement.style.setProperty

const documentWidth =
window.innerWidth - document.documentElement.clientWidth;
const scrollBarValue = documentWidth >= 0 ? documentWidth : 0;
document.documentElement.style.setProperty(
'--scrollbar-width',
${scrollBarValue}px
);

@AndrewJakubowicz
Copy link
Contributor

It's not clear what this question is asking.
What you've written sets a custom property --scrollbar-width on probably the root element, which is usually the html element, and is unchanged whether or not you use Lit.

@rajeevnttdata
Copy link
Author

document.documentElement.style.setProperty

Hi @AndrewJakubowicz

I just wanted to achieve javascript functionality in lit element. Like dynamically set width using

document.documentElement.style.setProperty is available in javascript.

In the same way, I need to implement a lit element.

@AndrewJakubowicz
Copy link
Contributor

Within a lit element you can call this.style.setProperty, because a lit element is an HTML element, so has the same API.

Live example of using setProperty: https://lit.dev/playground/#gist=65b28ac0aa24c43cfb3508542d2c8f34

However, for dynamic styles prefer styleMap and/or classMap. See documentation for more about declarative dynamic styles: https://lit.dev/docs/components/styles/#dynamic-classes-and-styles

@AndrewJakubowicz
Copy link
Contributor

Closing issue as I think I've answered above. Please re-open or open a new issue if you still have questions.

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

No branches or pull requests

2 participants