[英]How to set 'back to top' above footer after scroll to bottom
I use the code given below for my back to top option 我使用下面给出的代码作为我的返回页首选项
$(window).scroll(function() {
if ($(this).scrollTop()) {
$("#to-top").fadeIn();
} else {
$("#to-top").fadeOut();
}
if($(window).scrollTop() + $(window).height() < $(document).height() - $("#footer").height()) {
$('#to-top').css("position","fixed"); //resetting it
$('#to-top').css("bottom","0"); //resetting it
}
if($(window).scrollTop() + $(window).height() > $(document).height() - $("#footer").height()) {
$('#to-top').css("position","relative"); // make it related
$('#to-top').css("bottom","188px"); // 60 px, height of #toTop
}
});
$("#to-top").click(function() {
$("html, body").animate({scrollTop: 0}, 1000);
});
but it does not work while i scroll down, because my content has the position relative as well as i have a floting div which position is absolute.In above code i need to set the position of my content is absolute.If i do this the two content displace. 但是当我向下滚动时它不起作用,因为我的内容具有相对位置以及我的浮动div位置是绝对的。在上面的代码中,我需要设置内容的位置是绝对的。如果我这样做两个内容替换。 here is my html code:
这是我的html代码:
<a id="to-top" style="position:fixed;bottom:0px;right:15px;" href="#" title="Back to Top"><img src="../images/BackToTop_icon.jpg"/></a>
how can i fixed this problem.. 我该如何解决这个问题。
if you don't want to animate anything, then window.scrollTo(0,0)
will do. 如果您不想设置任何动画,那么
window.scrollTo(0,0)
将window.scrollTo(0,0)
。 (x coord, y coord). (x坐标,y坐标)。
If you want to animate it, then this will do: $('body').animate({scrollTop:0},2000);
如果要为其设置动画,则可以这样做:
$('body').animate({scrollTop:0},2000);
no need to create old html hash-anchors ( www.domain.com/index.html#paragraph2
), jQuery does the trick :) 无需创建旧的html哈希锚(
www.domain.com/index.html#paragraph2
就能解决问题:)
This is now correct and it works.... 现在这是正确的,并且可以正常工作。
$(document).ready(function() {
$("#to-top").css("display","none");
});
$(window).scroll(function() {
if ($(this).scrollTop()) {
$("#to-top").fadeIn();
} else {
$("#to-top").fadeOut();
}
if($(window).scrollTop() + $(window).height() < $(document).height() - $("#sc-main-footer").height()) {
$('#to-top').css("position","fixed"); //resetting it
$('#to-top').css("bottom","0"); //resetting it
}
if($(window).scrollTop() + $(window).height() > $(document).height() - $("#sc-main-footer").height()) {
$('#to-top').css("bottom","188px");
}
});
$("#to-top").click(function() {
$("html, body").animate({scrollTop: 0}, 1000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.