:その後
function animateBody() {
var hash = $(this).val();
var target_offset = $(hash).offset();
$('html, body').animate({scrollTop:target_offset.top}, 500);
}
、あなたはそれを2回再宣言することなく、複数のイベントに関数をバインドすることができます。
//Other JQuery/Javascript
function animateBody() {
var hash = $(this).val();
var target_offset = $(hash).offset();
$('html, body').animate({scrollTop:target_offset.top}, 500);
}
$("#jump_menu select option").click(animateBody);
$("#jump_menu select").change(animateBody);
//Other JQuery/Javascript
:
$("#jump_menu select option").click(animateBody);
$("#jump_menu select").change(animateBody);
結果として生じるが、このようなものを見ることができます
幸運を祈る!
唯一の問題は、誰かが上にスクロールして前のオプションを再選択しようとしたときに、再び発火しないようにすることです。 –
@George:その場合は、コードをスタンドアロンの名前付き関数で無名関数に入れ、処理したいイベントにバインドするだけです。 – sje397
@George:Edited。 – sje397