在CSS和HTML中平滑滚动
您好,我正在使用多个页面上的网站上工作,我想在某个页面上进行平滑滚动,但我不想使用HTML标签,因为它仅适用于此特定页面,而不是整个网站,这是我的代码。
{% if section.settings.display_product_detail_description == false and section.settings.display_product_reviews == false and section.settings.display_shipping_returns == false %}
{% assign tab5_active = true %}
{% endif %}
<div class="scroll-to-table">
<li class = "tab-title">
<a href="#product_attributes_table" class="tab-links {% if tab5_active %} active {% endif %}">
Specs
</a>
</li>
</div>
这是HTML的代码
div.scroll-to-table{
scroll-behavior: smooth;}
CSS代码
,以下是页面所做的所有 是跳跃而不是光滑的滚动。我已经尝试使用ID代替类,.scroll到croll-to.scroll to.scroll到table,并更改我从中称为CSS的元素,但没有运气
Hello I am working on my website with multiple pages and I want to do smooth scrolling on a certain page but I don't want to use the html tag because it will only be for this specific page and not the whole website here is my code.
{% if section.settings.display_product_detail_description == false and section.settings.display_product_reviews == false and section.settings.display_shipping_returns == false %}
{% assign tab5_active = true %}
{% endif %}
<div class="scroll-to-table">
<li class = "tab-title">
<a href="#product_attributes_table" class="tab-links {% if tab5_active %} active {% endif %}">
Specs
</a>
</li>
</div>
This is the code for the HTML
div.scroll-to-table{
scroll-behavior: smooth;}
And here is the code for the CSS
At the moment all that the page is doing is a jump and not a smooth scroll. I've tried using ID instead of Class, .scroll-to-table instead of div.scroll-to-table, and changing the element in which I call the CSS from but no luck
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用JavaScript IIFE(立即调用函数表达式)将
scroll-behaviour:平滑
添加到特定页面。这将把平滑的行为添加到运行此脚本的唯一页面。We can add
scroll-behaviour: smooth
to particular page by using javascript IIFE (Immediately Invoked Function Expression). This will add the smooth behaviour to the only page that runs this script.