查询:
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;