我在添加和删除类、在滚动上应用样式时遇到问题。
具体来说,当我向下滚动页面时:
is-red 的类仍然在第一个 .dot__outer 组中,当您向下滚动页面时应该将其删除,应该有一个组突出显示is-red 类滚动:
dot__outer 类的所有 div 上的类 is-redis-red 类添加到系列中的下一个 dot__outer。即,如果用户在第二个面板上,则第二个组应突出显示为红色圆点颜色:
is-red 类的 dot__outer 都应该是红色的$(function() {
function updateProgress() {
let dot = $(".dot");
let dotsBottom = $(".dots").offset().top + $(".dots").outerHeight();
let panelHeaderBottom =$(".panel-1").offset().top + $(".panel-1").outerHeight();
let panelRelatedTop = $(".panel-8").offset().top;
// If the `dot__outer` has a class of `is-active` the dot should also be red. By default, the dot and border should be white.
if (dot.parent().hasClass("is-red")) {
$(this).css("background", "red");
} else {
// If the position of the dots is less than the bottom of the header or greater than the top of the related section, the dots are white. Otherwise, the dots are black
if (dotsBottom < panelHeaderBottom || dotsBottom > panelRelatedTop) {
$(this).css("background", "#000");
} else {
$(this).css("background", "#fff");
}
}
$(".panel").each(function(index) {
let currentPosition = $(window).scrollTop();
let panelTop = $(this).offset().top;
let panelBottom = $(this).offset().top + $(this).outerHeight();
if ((currentPosition > panelTop) && (currentPosition < panelBottom)) {
$(".dot__outer").removeClass("is-red");
$(".dot__outer").eq(index).addClass("is-red");
} else {
$(".dot__outer").eq(0).addClass("is-red");
}
});
}
$(window).scroll(function() {
updateProgress();
});
});
<div class="panels">
<div class="panel panel-1">Panel #1</div>
<div class="panel panel-2">Panel #2</div>
<div class="panel panel-3">Panel #3</div>
<div class="panel panel-4">Panel #4</div>
<div class="panel panel-5">Panel #5</div>
<div class="panel panel-6">Panel #6</div>
<div class="panel panel-7">Panel #7</div>
<div class="panel panel-8">Panel #8</div>
</div>
<div class="dots">
<div class="dot__outer is-red">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
<div class="dot__outer">
<div class="dot"></div>
</div>
</div>
https://codepen.io/yacoubian/pen/PBOVKw?editors=1010
更新
滚动问题已修复,codpen 已更新。
最佳答案
这是您可能采用的另一种方法:
function updateProgress() {
let dotsBottom = $(".dots").offset().top + $(".dots").outerHeight();
let dotBorder = $(".dot__outer");
let headerBottom = $(".panel-1").offset().top + $(".panel-1").outerHeight();
let relatedTop = $(".panel-8").offset().top;
$(".panel").each(function(index) {
let currentPosition = $(window).scrollTop();
let panelTop = $(this).offset().top;
let panelBottom = $(this).offset().top + $(this).outerHeight();
if (currentPosition > panelTop && currentPosition < panelBottom) {
dotBorder.removeClass("is-red");
dotBorder.eq(index).addClass("is-red").children().css("background", "red");
if (dotsBottom < headerBottom || dotsBottom > relatedTop) {
dotBorder.not(".is-red").children().css("background", "#fff");
} else {
dotBorder.not(".is-active").children().css("background", "#000");
}
}
});
}
关于javascript - 添加和删除类,在滚动上应用样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51599958/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我有一大串格式化数据(例如JSON),我想使用Psychinruby同时保留格式转储到YAML。基本上,我希望JSON使用literalstyle出现在YAML中:---json:|{"page":1,"results":["item","another"],"total_pages":0}但是,当我使用YAML.dump时,它不使用文字样式。我得到这样的东西:---json:!"{\n\"page\":1,\n\"results\":[\n\"item\",\"another\"\n],\n\"total_pages\":0\n}\n"我如何告诉Psych以想要的样式转储标量?解
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R