JavaScript Language Switcher update w/ css display
Simple JavaScript Language Switcher, use javascript switch language.
Photo by Markus Winkler on Unsplash
after quite a bit of searching, I decided to create a naive one
you can just fork it to use it
simple demo
jQuery Hide & Show
At the first I thought I can use jQuery’s .hide()
and .show()
to achieve the result I want.
First Naive Version
HTML
|
|
JS
|
|
Then I quickly found that the user with javascript disabled or slow load in would result in seeing the original HTML w/ multiple langs not being hidden.
So I’ve tried to initialize the hidden lang by set CSS visible
to hidden
.
CSS Visibility
|
|
But it resulted in a disordered layout.(You can regard it as what when we set the colour: white;
to cover something up)
Finally with the help of another style attribution, display
, I am able to achieve what I want - to set up a multilingual site and handle the error when users have a low load-in speed or JS disabled.
CSS Display
|
|
Result: Simple JavaScript Language Switcher w/ css display (chienhsiang-hung.github.io)
How to use it
The example was shown for TW-EN site.
Set up your HTML like this:
|
|
Put this in <head>
part of your HTML:
|
|
And this in <body>
part of you HTML:
|
|
Support
It’s always appreciated if you would like to buy me a cofee to support this API. Thank you :)
contact me: Hung, Chien-Hsiang (chienhsiang-hung.github.io)