JQuery:
k = get the element that is being clicked on.
$('k').click(function() { //based on the element and where it should scroll to
$('body,html').animate({scrollTo: /*target*/},800); /*target==where its scrolling to*/
});
HTML:
<a id="a1" class="pointto">1</a>
<a id="a2" class="pointto">2</a>
<a id="a3" class="pointto">3</a>
<a id="a4" class="pointto">4</a>
<a id="a5" class="pointto">5</a>
<a name="1">1. This is where it scrolls to</a>
<a name="2">2. This is where it scrolls to</a>
<a name="3">3. This is where it scrolls to</a>
<a name="4">4. This is where it scrolls to</a>
<a name="5">5. This is where it scrolls to</a>
私が達成しようとしているのは、単一の「click()」関数を使用して、尊敬されるリンクターゲットまでスクロールすることです。
たとえば、a1
をクリックすると、 までスクロールし1
ます。がクリックされた場合は、次のようa2
にスクロールし2
ます...
click()
ページでこのコードをすべて使用していますが、以下の関数を追加するとエラーが発生します。
$(function() {
$('#theEmail').keyup(function() {
if (this.value.match(/[^\-_a-zA-Z0-9 ]/g)) {
this.value = this.value.replace(/[^\-_a-zA-Z0-9 ]/g, '');
}
});
$(".pointto").mouseover(function() {
$(this).addClass("Hover");
});
$(".pointto").mouseout(function() {
$(this).removeClass("Hover").removeClass("Pressed");
});
$(".pointto").mousedown(function() {
$(this).addClass("Pressed");
});
$(".pointto").mouseup(function() {
$(this).removeClass("Pressed");
});
$('.pointto').click(function() {
var nn = parseInt($(this).attr('id'), 10);
var top = $('a[name='"+nn+"']').offset().top;
$('body,html').animate({scrollTop:top},800);
});
});
Error: Expected ')' in line: var top = $('a[name='"+nn+"']').offset().top;