Поэтому у меня есть следующий веб-сайт: http://www.gameplay-universe.uphero.com/
Вы можете увидеть ссылку "Пропустить к контенту". Я хочу, когда он щелкнул страницу, чтобы прокрутить до div#content
. Я использую последнюю версию jQuery. Как я могу это достичь?
Хорошо, вот решение, которое я нашел:
$(document).ready(function() {
// Click event for any anchor tag that href starts with #
$('a[href^="#"]').click(function(event) {
// The id of the section we want to go to.
var id = $(this).attr("href");
// An offset to push the content down from the top.
var offset = 60;
// Our scroll target : the top position of the
// section that has the id referenced by our href.
var target = $(id).offset().top - offset;
// The magic...smooth scrollin' goodness.
$('html, body').animate({scrollTop:target}, 500);
//prevent the page from jumping down to our section.
event.preventDefault();
});
});
Это сработало для меня.
$("li a").click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 1000);
return false;
});
это будет работать для всех ссылок внутри элементов li.
div#content onclick li.skip a
к div#content onclick li.skip a
?
Вот сценарий, который мне нравится использовать, когда я хочу включить "эффект прокрутки" типа JQuery.
$(document).scrollTop($('div#content').offset().top)