Skip to content

Instantly share code, notes, and snippets.

@motsu0
Last active March 9, 2023 06:27
Show Gist options
  • Save motsu0/593c858f44b4ac4d930913067c6c77de to your computer and use it in GitHub Desktop.
Save motsu0/593c858f44b4ac4d930913067c6c77de to your computer and use it in GitHub Desktop.
<div id="demo1">
<img src="pathto/sign1.png" alt="交通標識" class="ImageSelector__option" data-value="1">
<img src="pathto/sign2.png" alt="交通標識" class="ImageSelector__option" data-value="2">
<img src="pathto/sign3.png" alt="交通標識" class="ImageSelector__option" data-value="3">
<img src="pathto/sign4.png" alt="交通標識" class="ImageSelector__option" data-value="4">
<img src="pathto/sign5.png" alt="交通標識" class="ImageSelector__option" data-value="5">
<img src="pathto/sign6.png" alt="交通標識" class="ImageSelector__option" data-value="6">
<img src="pathto/sign7.png" alt="交通標識" class="ImageSelector__option" data-value="7">
<img src="pathto/sign8.png" alt="交通標識" class="ImageSelector__option" data-value="8">
<img src="pathto/sign9.png" alt="交通標識" class="ImageSelector__option" data-value="9">
</div>
const el_demo1 = document.getElementById('demo1');
const image_selector1 = new ImageSelector(el_demo1);
<div id="demo2">
<img src="pathto/sign1.png" alt="交通標識" class="ImageSelector__option" data-value="1">
<img src="pathto/sign2.png" alt="交通標識" class="ImageSelector__option" data-value="2">
<img src="pathto/sign3.png" alt="交通標識" class="ImageSelector__option ImageSelector__s-selected" data-value="3">
<img src="pathto/sign4.png" alt="交通標識" class="ImageSelector__option" data-value="4">
<img src="pathto/sign5.png" alt="交通標識" class="ImageSelector__option" data-value="5">
<img src="pathto/sign6.png" alt="交通標識" class="ImageSelector__option" data-value="6">
<img src="pathto/sign7.png" alt="交通標識" class="ImageSelector__option" data-value="7">
<img src="pathto/sign8.png" alt="交通標識" class="ImageSelector__option" data-value="8">
<img src="pathto/sign9.png" alt="交通標識" class="ImageSelector__option" data-value="9">
</div>
const el_demo2 = document.getElementById('demo2');
const image_selector2 = new ImageSelector(el_demo2);
image_selector2.setHeight(600);
.demo-flex{
display: flex;
align-items: center;
}
.national-flag{
box-sizing: border-box;
margin-right: 4px;
border: 1px solid #777;
}
<div id="demo3">
<div class="ImageSelector__option demo-flex" data-value="japan">
<img src="pathto/japan.png" alt="日本の国旗" class="national-flag">
Japanese
</div>
<div class="ImageSelector__option demo-flex" data-value="usa">
<img src="pathto/usa.png" alt="アメリカ合衆国の国旗" class="national-flag">
English
</div>
<div class="ImageSelector__option demo-flex" data-value="china">
<img src="pathto/china.png" alt="中国の国旗" class="national-flag">
Chinese
</div>
</div>
<div id="output3"></div>
const el_output3 = document.getElementById('output3');
const el_demo3 = document.getElementById('demo3');
const image_selector3 = new ImageSelector(el_demo3);
image_selector3.setOnChange(demoFunc3);
function demoFunc3(){
el_output3.textContent = 'value=' + image_selector3.value;
}
<div id="demo4">
<div class="ImageSelector__option demo-flex" data-value="japan">
<img src="pathto/japan.png" alt="日本の国旗" class="national-flag">
Japanese
</div>
<div class="ImageSelector__option demo-flex" data-value="usa">
<img src="pathto/usa.png" alt="アメリカ合衆国の国旗" class="national-flag">
English
</div>
<div class="ImageSelector__option demo-flex" data-value="china">
<img src="pathto/china.png" alt="中国の国旗" class="national-flag">
Chinese
</div>
</div>
const el_demo4 = document.getElementById('demo4');
const image_selector4 = new ImageSelector(el_demo4);
image_selector4.setValue('usa');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment