Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在滚动期间,需要通过单击标记来固定表_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 在滚动期间,需要通过单击标记来固定表

Javascript 在滚动期间,需要通过单击标记来固定表,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我的滚动有点问题。 我有3个表,其中一个我想在滚动超过特定距离后修复 var $table = $("#thead"), $window = $(window), distance = $table.offset().top; text=$("div.text2"), textdistance=text.offset().top; $window.scroll(function () { var wdistance = $window.scrollTop(); if (wdistance

我的滚动有点问题。 我有3个表,其中一个我想在滚动超过特定距离后修复

var $table = $("#thead"),
$window = $(window),
distance = $table.offset().top;
text=$("div.text2"),
textdistance=text.offset().top;

$window.scroll(function () {
var wdistance = $window.scrollTop();

 if (wdistance > distance) {
    if( wdistance < textdistance )
    {table.addClass('fixed');}
    else {
    table.removeClass('fixed');
    }
  }else{
    table.removeClass('fixed'); 
 }
var$table=$(“#thead”),
$window=$(window),
距离=$table.offset().top;
text=$(“div.text2”),
text距离=text.offset().top;
$window.scroll(函数(){
var wdistance=$window.scrollTop();
如果(距离>距离){
if(距离<文本距离)
{table.addClass('fixed');}
否则{
表.removeClass(“固定”);
}
}否则{
表.removeClass(“固定”);
}
}))

这是我的第一个演示

我想说的是,当这个“if”正确时,当滚动页面时,带有“thead”id的div的位置就会固定在其他表的顶部。id为“first”的div完成后,返回上一个位置。 还有一个问题是点击更多细节后出现的,因为css中id为“more detail”的div在点击更多细节与否时会滚动显示:block,display:none,,id为“thead”的表格

这是我的第二个演示

当您使用$variablename时,请在使用varaible时始终使用
$
符号。在代码中,您指定了变量
var$table
,然后将其简单地用作
table
,而不使用
$

固定小提琴:
更新的小提琴:纠正它

高度()


tnx你解决了我的一个问题,你不知道我的另一个问题吗?请澄清它们。在id为“first”完成div后,我不会得到其他问题我想把固定位置的桌子放回原来的位置。好的@mimi。等待我的回答。我解决了问题,但这样在点击更多细节时会产生另一个问题。id为“thead”的桌子的位置仍然是固定的。
textdistance=distance + $tableBody.height();