Is there anyway i can make that thing ?
so if we scroll an option it will scroll down where i want ?
eg:
<select name="test>
<option>a</option>
<option>b</option>
</select>
Is there anyway i can make that thing ?
so if we scroll an option it will scroll down where i want ?
eg:
<select name="test>
<option>a</option>
<option>b</option>
</select>
はい、マークアップにselect
オプションが反映されていると仮定すると、次の HTML を考えると、お勧めします。
<select id="test">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
<div id="a">
<p>Contents in #a</p>
</div>
<div id="b">
<p>Contents in #b</p>
</div>
<div id="c">
<p>Contents in #c</p>
</div>
あなたが使用できること:
var select = document.getElementById('test');
select.onchange = function(){
window.location.hash = this.getElementsByTagName('option')[this.selectedIndex].value;
};
または:
var select = document.getElementById('test');
select.onchange = function(){
var id = this.getElementsByTagName('option')[this.selectedIndex].value,
el = document.getElementById(id),
top = el.offsetTop;
window.scrollTo(0,top);
};