gpt4 book ai didi

javascript - 无法访问 "after ' 返回'交战

转载 作者:行者123 更新时间:2023-11-28 01:52:26 25 4
gpt4 key购买 nike

我似乎无法修复这些警告:

  1. 将其与之前第 7、9 和 10 行的“var”语句结合起来。
  2. “返回”后无法访问“- 位于 if ($window.width() <= 770) { return;

这是脚本:

     //StickyBox
$(function () {
$.fn.scrollBottom = function () {
return $(document).height() - this.scrollTop() - this.height();
};
var $StickyBox = $('.detailsBox');
var $window = $(window);

$window.bind("scroll resize", function () {
var gap = $window.height() - $StickyBox.height() - 10;
var footer = 288 - $window.scrollBottom();
var scrollTop = $window.scrollTop();

$StickyBox.css({
top: 'auto',
bottom: 'auto'
});

if ($window.width() <= 770) {
return;
$StickyBox.css({
top: '0',
bottom: 'auto'
});
}

if (scrollTop < 50) {
$StickyBox.css({
bottom: "auto"
});

} else if (footer > gap - 100) {
$StickyBox.css({
top: "auto",
bottom: footer + "px"
});

} else {
$StickyBox.css({
top: 80,
bottom: "auto"
});
}
});
});

还有没有办法更改以下脚本,所以我不需要给出数字,但它应该知道标题何时到达框,然后固定其位置?

if (scrollTop < 50) {
$StickyBox.css({
bottom: "auto"
});

上述代码的实时示例:http://loaidesign.co.uk/php/projects.php?project=1

最佳答案

问题是,如果这个“if”为真,那么它将始终返回,并且接下来的几行代码永远无法运行。

if ($window.width() <= 770) {
return;
$StickyBox.css({
top: '0',
bottom: 'auto'
});
}

sof 如果你想设置top:0 和bottom:auto 你必须在后面加上回车符。如果您只想在不正确的情况下设置顶部和底部,那么您就错过了 else:

if ($window.width() <= 770) {
return;
}else{
$StickyBox.css({
top: '0',
bottom: 'auto'
});
}

也许你的意思是

if ($window.width() <= 770) {

$StickyBox.css({
top: '0',
bottom: 'auto'
});
return;
}

关于javascript - 无法访问 "after ' 返回'交战,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19549411/

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