I am working on a single page applications that has a bunch of hidden divs, binded (or is it bound?) to KnockoutJS with visible:
. When page loads, they all momentarily flash on screen. I have tried moving my JS into the <head></head>
, but that had no effect, so loading JS at the bottom of the page is not what's causing it.
Unfortunately, visible:
binding does not propagate to CSS display
attribute, so I can not use display: none;
on page load, or visible:
will not work at all. Unless... I load the page with display: none;
and then change it the very first time I show the div to a user.
But is there a more elegant way to achieve this?
A gutter margin ensures the binding doesn't hide text. The default gutter position is left.
KO is able to create a two-way binding if you use value to link a form element to an Observable property, so that the changes between them are exchanged among them. If you refer a simple property on ViewModel, KO will set the form element's initial state to property value.
The visible binding shows or hides the target DOM element or widget depending on the View-Model value. If the value is true , the target DOM element is shown. If the value is false , the target DOM element is hidden—its display CSS attribute is set to none .
Essentially a binding or a data binding is a way to link your ViewModels to your Views(templates) and vice versa. KnockoutJS uses two-way data binding, which means changes to your ViewModel influence the View and changes to your View can influence the ViewModel.
Wth KnockoutJS, I work around this problem by defining a CSS class called hidden
with display:none
, then I'll add this class and binding to the flashing container:
class="hidden" data-bind="css: { hidden: false }"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With