1

だから私はサイトギャラリーのようなものを手に入れようとしています。ページ全体に広がる記事があり、ユーザーからアクションを取得するとサイトが次の記事にジャンプするという考えです。私はこれまでに多くの作業を行ってきましたが、javascript の背後にいるのは数日です。jquery を使用しており、コードは次のとおりです。

$('body').ready(function () {
    var tpScroll = 0;
    var SelArticles = $('#content').find('.bgjs');
    var NumArticles = SelArticles.length;
    window.location.hash = SelArticles.first().attr('id');


    $(window).bind('mousewheel', function (event, delta, deltaX, deltaY) {
        event.preventDefault();
        console.log(delta, deltaX, deltaY);
        console.log(tpScroll);
        if (delta < 0) {
            if (tpScroll >= (NumArticles - 1)) {
                tpScroll = 0;
            } else {
                tpScroll = tpScroll + 1;
            }
            var pgid = SelArticles.eq(tpScroll).attr('id');
            window.location.hash = pgid;
        } else {
            if (tpScroll <= 0) {
                tpScroll = (NumArticles - 1);
            } else {
                tpScroll = tpScroll - 1;
            }
            var pgid = SelArticles.eq(tpScroll).attr('id');

            window.location.hash = pgid;
        }
    });
});

マウスホイール イベントを処理してハッシュを変更することはできましたが、コンテンツへのデフォルトのスクロールを防止して、スムーズなアニメーションを追加したいと考えています。ご覧のとおり、私はjavascriptのモンスターではありません(jqueryでもありません)が、それは一種の機能です。この動作を防止したり、回避したりできるかどうかさえわかりません...何か提案はありますか?

4

1 に答える 1