我想要滚动到一个网页的底部轻松动画点击我的主页底部我已经插入了一个名为墙的link.In类我有我的菜单作为主页,墙,联系人,overview.If我点击‘墙’从我的主页它应该向下滚动到页面底部(记住div类墙是在同一主页上),当我在另一个页面上说联系人,当我点击我的菜单中的墙时,主页应该被加载,然后应该向下滚动(记住,如果主页被点击,页面将打开,从不滚动).Is有任何方法这样做吗?我用html5设计了网站,并使用了以下代码
<script type="text/javascript">
function pageScroll() {
window.scrollBy(0,50); // horizontal and vertical scroll increments
scrolldelay = setTimeout('pageScroll()',20);
// scrolls every 20 milliseconds
}
</script>
<body onload="pageScroll()">但问题是,页面向下滚动,永远不会让滚动停止.Even,如果我们向上滚动,它会返回到bottom...Is,有没有办法只滚动一次?
我几乎不知道怎么拼写jquery...Need help。
发布于 2012-12-20 21:14:27
它很简单,就像
$('html, body').animate({
scrollTop: $(document).height()-$(window).height()
});要滚动到特定的Id,请使用以下命令
$("html, body").animate({
scrollTop: $("#theID").scrollTop()
}, 1000);发布于 2012-12-20 21:19:42
从字面上看,在谷歌上搜索"scroll with easing jquery“后的第一个结果是"Smooth vertical or horizontal page scrolling with JQuery",它做的正是你想要的。研究该页面的内容,并记住在提出问题之前进行研究。
来自该页面的Here's the vertical scroll示例,下面是完成所有工作的javascript代码。
$(function() {
$('ul.nav a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500,'easeInOutExpo');
/*
if you don't want to use the easing effects:
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1000);
*/
event.preventDefault();
});
});如果你是JQuery的新手,不知道从哪里开始,我建议你从他们的tutorials page开始学习基础知识。我还想指出的是,建议使用unobtrusive javascript,否则在HTML中混合使用javascript函数调用会变得很混乱。
另外,我不确定你是否知道,但是如果你想要link in javascript files到你的html,你可以在头部或身体这样做:
<script type="text/javascript" src="external_javascript.js"></script>祝你编码愉快!
https://stackoverflow.com/questions/13972864
复制相似问题