javascript - Javascript 从左到右滑动
问题描述
我想要:
- 从标题的缩写到写出的含义+副标题的展开动画,其中包含有关该主标题的信息。
编辑:示例:S3 推出“固化固态”,并在发生这种情况后立即使副标题的透明度逐渐增加
单击时将其从左向右展开(从而显示隐藏的基础信息)。
我在 jsfiddle 中所做的似乎很不稳定。(它在两个部分中打开辅助文本)。
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Fira+Sans+Condensed&display=swap" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class = "s3notebox">
<h1>S3</h1>
</div>
<div class = "sub-headings">
<p>S3 notes go in this section which should flare out.</p>
</div>
CSS:
.s3notebox{
background-color: rgba(174, 214, 241, 0.5);
display: flex, inline-block;
white-space: nowrap;
height: 3em;
width: 10vw;
font-family: 'Poppins', sans-serif;
border-left: 6px solid #48C9B0;
border-radius: 2px;
}
.sub-headings{
white-space: nowrap;
height: 3em;
width: 10vw;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
border-left: 6px solid yellow;
position:absolute;
}
JS:
$(document).ready(function(){
$(".s3notebox").click(function(){
$(".sub-headings").slideToggle();
});
});
解决方案
我刚刚写了一个解决方案。在这里,我对您的 html、css 和 js 文件进行了一些更改。希望它会帮助你。
$(document).ready(function(){
$(".s3notebox").click(function(){
$("#subHeading").toggleClass('left-to-right-slide');
});
});
.s3notebox{
background-color: rgba(174, 214, 241, 0.5);
display: flex, inline-block;
white-space: nowrap;
height: 3em;
width: 10vw;
font-family: 'Poppins', sans-serif;
border-left: 6px solid #48C9B0;
border-radius: 2px;
}
.sub-headings{
white-space: nowrap;
height: 3em;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
border-left: 6px solid yellow;
position: absolute;
transition: all 0.33s ease;
left: -100%;
}
.left-to-right-slide {
left: 1%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = "s3notebox">
<h1>S3</h1>
</div>
<div id="subHeading" class = "sub-headings">
<p>S3 notes go in this section which should flare out.</p>
</div>
推荐阅读
- python - 如何快速不返回加盐密文,而是返回密文的未加盐版本?
- java - 如何在 java 中使用 jdbc 编写选择查询需要检查 COLUMN 是否为 NULL?
- sql-server - 按名称删除分区 sql server
- ios - 处理多个任务时如何跟踪进度和增加进度视图的计数?
- python - 使用 matplotlib 增加绘图和标题之间的空间
- azure-cognitive-search - Azure 搜索排序,如 localeCompare javascript 功能
- javascript - 如何将图像和数据添加到 Firebase
- c# - 如何将带有滑块的 HH:mm 格式设置为文本框
- xpath - XPath 1.0 代码选择了错误的最大值
- c# - 删除 linq 中的循环导致性能降低