1

マウスオーバーで垂直にスクロールするjqueryのスクロールメニューがあります:(その一部は、スクロールして表示されるまで非表示になります)

<script type="text/javascript">
$(document).ready(function() {

    //Scroll the menu on mouse move above the #sidebar layer
    $('#sidebar').mousemove(function(e) {

        //Sidebar Offset, Top value
        var s_top = parseInt($('#sidebar').offset().top);

        //Sidebar Offset, Bottom value
        var s_bottom = parseInt($('#sidebar').height() + s_top);

        //Roughly calculate the height of the menu by multiply height of a single LI with the total of LIs
        var mheight = parseInt($('#menu li').height() * $('#menu li').length);


        //Calculate the top value
        //This equation is not the perfect, but it 's very close    
        var top_value = Math.round(((s_top - e.pageY) / 100) * mheight / 2);

        //Animate the #menu by chaging the top value
        $('#menu').animate({
            top: top_value
        }, {
            queue: false,
            duration: 5000
        });
    });
});​
</script>

次に、検索と強調表示の jquery スクリプトを使用して、スクロール メニューで名前を検索しています。

<script type="text/javascript">
$(function() {
    $('#text-search').bind('keyup change', function(ev) {
        // pull in the new value
        var searchTerm = $(this).val();)

    // remove any old highlighted terms
    $('#sidebar').removeHighlight();

    // disable highlighting if empty
    if (searchTerm) {
        // highlight the new term
        $('#sidebar').highlight(searchTerm);
    }
    });
});​
</script>

ただし、私の問題は次のとおりです。検索語を入力すると、表示されているメニュー項目のみが強調表示されます。div内の検索語にjqueryを自動的にスクロールさせるにはどうすればよいですか?

4

1 に答える 1

1

次の行に沿ったもの:

var searchTermTop,
    searchTermBottom;

searchTermTop = searchTerm.offsetParent().top;
searchTermBottom = searchTerm.offsetParent().bottom;

if(searchTermTop < 0){
    //set the menu scroll to it's current scroll + the searchTermTop
}
if(searchTermBottom > mheight){
    //set the menu scroll to it's current scroll + the searchTermBottom
}

それらの線に沿った何か。詳細が必要な場合はお知らせください。今オフィスを使い果たす必要があるか、詳細を少し記入します。

于 2012-08-16T21:45:28.883 に答える