gpt4 book ai didi

javascript - 出现页脚时重新定位滚动到顶部按钮

转载 作者:太空宇宙 更新时间:2023-11-04 03:01:05 24 4
gpt4 key购买 nike

必须有一种方法可以让我的滚动到顶部按钮在网站用户向下滚动到足以让页脚出现在屏幕上时立即处理#footer 容器的顶部,对吗?现在它只想固定在屏幕的左下角——这是有道理的,但必须有一种方法来做我想做的事,作为一个新手,我似乎无法弄明白!任何帮助将非常感激。谢谢!

我网站上我们使用按钮的页面:http://joriebreonn.com/blogs/jb-blog/35009473-its-a-knockout

这是我的脚本:

jQuery(document).ready(function($){
// browser window scroll (in pixels) after which the "back to top" link is shown
var offset = 300,
//browser window scroll (in pixels) after which the "back to top" link opacity is reduced
offset_opacity = 1200,
//duration of the top scrolling animation (in ms)
scroll_top_duration = 700,
//grab the "back to top" link
$back_to_top = $('.cd-top');

//hide or show the "back to top" link
$(window).scroll(function(){
( $(this).scrollTop() > offset ) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out');
if( $(this).scrollTop() > offset_opacity ) {
$back_to_top.addClass('cd-fade-out');
}
});

//smooth scroll to top
$back_to_top.on('click', function(event){
event.preventDefault();
$('body,html').animate({
scrollTop: 0 ,
}, scroll_top_duration
);
});

});

和相关的CSS:

.cd-top {
display: inline-block;
height: 40px;
width: 40px;
position: fixed;
bottom: 40px;
right: 10px;
box-shadow: none;
/* image replacement properties */
overflow: hidden;
text-indent: 100%;
white-space: nowrap;
background: url('litebox-next.png') no-repeat center 50%;
background-size: 40px;
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
visibility: hidden;
opacity: 0;
-webkit-transition: opacity .3s 0s, visibility 0s .3s;
-moz-transition: opacity .3s 0s, visibility 0s .3s;
transition: opacity .3s 0s, visibility 0s .3s;
}
.cd-top.cd-is-visible, .cd-top.cd-fade-out, .no-touch .cd-top:hover {
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
-moz-transition: opacity .3s 0s, visibility 0s 0s;
transition: opacity .3s 0s, visibility 0s 0s;
}
.cd-top.cd-is-visible {
/* the button becomes visible */
visibility: visible;
opacity: 1;
}
.cd-top.cd-fade-out {
/* if the user keeps scrolling down, the button is out of focus and becomes less visible */
opacity: .335;
}

.cd-top:hover {
background-color: transparent;
opacity: 1!important;
}

和 html:

<a href="#0" class="cd-top">Top</a>

最佳答案

您的目标是让位于页脚顶部的“滚动到顶部”按钮可点击吗?因为为此您需要做的就是将按钮的 z-index(一个 CSS 属性)设置为 100 或更高,以将其置于页脚之上。
如果你想将它移到页脚上方,我相信你可以在 $(window).scroll() 中放置第二个条件,检查 scrollTop() 是否接近页面末尾(通过将它与 $(document) 进行比较)。 height() ),然后将按钮的“底部”值设置为更高的值(例如使用 $back_to_top.css("bottom", "200") )。

关于javascript - 出现页脚时重新定位滚动到顶部按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31306222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com