これは、1つのページ(2つのdiv)、主にスプラッシュ画面を取得しようとしています。「サイトを入力」をクリックするとスムーズに「メインサイト」にスクロールします。しかし、要素へのスムーズなスクロールではなく、ジャンプします。scrollIntoViewによるスムーススクロール効果 - Javascript
このジャンプ効果なしでスムーズにスクロールするにはどうすればよいですか?あなたがボタンをクリックすると、それは次のdivにジャンプしますが、私はそれがスムーズにスクロールするのではなく、次のdivにジャンプする必要が
splash = document.getElementById('intro');
content = document.getElementById('content');
function enterSite(){
\t content.scrollIntoView({behaviour: "smooth"});
}
body {
font-family: 'Archivo Narrow', sans-serif;
margin: 0 auto;
width: 100%;
height: 100%;
}
html, body {
overflow: hidden;
}
main {
width: 100%;
height: 100%;
position: relative;
}
#intro {
background-image: url(https://i.imgsafe.org/51d0cf26df.jpg);
background-repeat: no-repeat;
background-size: cover;
display: flex;
text-align: center;
height: 100%;
}
#splash {
margin: auto;
width: 40%;
background-color: rgba(56,56,56,0.4);
border-radius: 50px 50px;
}
#splash-p {
width: 70%;
font-size: 1.2em;
line-height: 1.5em;
margin: auto;
text-align: center;
padding-top: 10px;
color: #fff;
}
.btn {
width: 35%;
margin: auto;
margin-top: 10px;
margin-bottom: 10px;
}
/* Main Content Page */
article {
position: absolute;
width: 100%;
height: 100%;
background-color: red;
}
<div id="intro">
\t \t \t <div id="splash">
\t \t \t <p id="splash-p">Just a load of text repeated</p>
\t \t \t <input type="image" src="Images/Button.png" class="btn" onclick="enterSite()">
\t \t \t </div>
\t \t </div>
\t \t <article id="content">
\t \t \t
\t \t \t Just a load of text repeated
\t \t </article>
:ここ
は私の抜粋です、純粋なjavascriptを使用して、私が見た他のどこにでもプラグインがあるか、またはjqueryを使用しているようです。
私はその質問を見ましたが、滑らかなスクロールではありません。私はちょうどjavascriptをあきらめて、CSSを使用する必要があると思います。 – Ricky
しかし、私が必要としていることを理解していれば、CSSだけでスクロールを制御することはできないと思います。とにかくそれは一般的なパターンです、あなたはまた、この記事を見ているかもしれません:https://www.sitepoint.com/smooth-scrolling-vanilla-javascript/ – christo
これは受け入れられた答えですか? JAVASCRIPTはjqueryではなく、彼は言った。誰もがjQueryを使ってjavascriptの質問に答える熱意は本当に私を殺します。 – codemon