html - 好奇将 html 内容设置为消失或随内容滚动而不覆盖内容
问题描述
编码新手,但想给我的网站留下深刻印象。
当前有一个“在此页面上”HTML 嵌入元素,当用户向下滚动页面时,我希望它消失。
我有左侧的元素,并且知道如何将其设置为固定。但是,这会使其他内容消失在元素后面。所以将 CSS 定位保持在静态,不要介意。
只是好奇如果我想让它随着内容滚动但在一定时间后或当用户通常向下滚动时消失,代码会是什么样子。
<style>
.sidebar-content
{
position:static;
background-color:#F9F9F9;
padding:15px;
text-decoration: none;
font-weight: 300;
font-size:20px;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, "sans-serif";
}
h2 {font-weight:400px;
color: #460E72;
font-size: x-large;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}
a:link {text-decoration:none;
color:#B6B6BA;
}
a:visited {text-decoration:none;
color:#404041;
}
a:hover {color:#404041;
background-color:#eeeeee;
cursor: pointer;
}
a:active {text-decoration:none;
color:#FF6712;}
<style>
.sidebar-content
{
top: 0;
position:fixed;
width: 256px;
max-widtH:296px;
left: - 275px;
transition:top 0.3s;
}
</style>
<div class="sidebar-content">
<h2>On this Page </h2>
<hr>
<a href="https://tnucii.weebly.com/blackboard-login--course-access.html#BlackboardLoginSteps">Blackboard Login Steps</a>
<br />
<a href="https://tnucii.weebly.com/blackboard-login--course-access.html#TroubleshootingLoginIssues">Troubleshooting Login Issues</a>
<br />
</div>
解决方案
仅使用 css 或 HTML 无法解决此问题。你必须使用js。
用户向下滚动 100 像素后,此代码将使您的对象消失。
$(window).bind('scroll', function() {
if ($(window).scrollTop() > 100) {
$('#divID').hide();
}
else {
$('#divID').show();
}
});
推荐阅读
- arrays - livewire和laravel中的多维数组访问
- sql - 用于将whatsapp 数据传输到 SQL 或其他数据库的 ETL
- entity-framework-core - EF Core 诊断 - 每个上下文实例的查询计数
- cors - CORS vs CORB,有什么区别?
- content-management-system - 如何从 CMS 存储和检索静态 json 和 html 文件?
- c++ - CMake - 在函数中...... - 对......函数的未定义引用
- r - R 代码正在使用 data.frame 函数运行,但是,不能编织成 pdf
- matlab - matlab app plot 在需要标准 2d 图时创建 3D 图
- python - 为什么在 python 烧瓶中使用 Selenium 会出现 No such element 异常?
- python - 时间数据与ec2实例中的python datetime格式不匹配