Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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,我使用html、css和Jquery创建了一个模式窗口。 每当模式内容较长时,向下滚动会使模式标题变为最顶部 我希望即使内容向下滚动,模式标题仍保持在其原始位置(如在fixed中) 我尝试使用-position:fixed作为css类模式头的一个随机尝试,但它没有按预期工作 我将代码附加到代码片段中 $(function () { const openModals = []; $('.modal-button').click(e => { e.preventDefault(

我使用html、css和Jquery创建了一个模式窗口。 每当模式内容较长时,向下滚动会使模式标题变为最顶部

我希望即使内容向下滚动,模式标题仍保持在其原始位置(如在fixed中)

我尝试使用-position:fixed作为css类模式头的一个随机尝试,但它没有按预期工作

我将代码附加到代码片段中

$(function () {
  const openModals = [];
  $('.modal-button').click(e => {
    e.preventDefault();
    $(e.target).closest('.modal').add('body').addClass('open');
    openModals.push($($(e.target).attr('href')).show());
  });
  $(window).add('.close').click(e => {
    e.stopPropagation();
    if ($(e.target).is('.modal, .close')) {
      const closing = openModals.pop().addClass('modal-content-active');
      setTimeout(() => {closing.hide().removeClass('modal-content-active')}, 400);
      if (openModals.length > 0) {
        openModals[openModals.length - 1].removeClass('open');
      } else $('body').removeClass('open');
    }
  });
});

×
模态头
什么是Lorem Ipsum?
Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是行业标准的虚拟文本,当时一位不知名的印刷商拿起一个打印工具,将其拼凑成一本打印样本书。它不仅存活了五个世纪,而且还跨越到电子排版,基本上保持不变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表单的发布而流行,最近随着Aldus PageMaker等桌面出版软件的发布,包括Lorem Ipsum版本。
我们为什么要用它?
读者在查看页面布局时会被页面的可读内容分散注意力,这是一个早已确定的事实。使用Lorem Ipsum的意义在于,它的字母分布或多或少是正态的,而不是使用“此处内容,此处内容”,使其看起来像可读的英语。许多桌面发布软件包和网页编辑器现在使用Lorem Ipsum作为默认模型文本,搜索“Lorem Ipsum”将发现许多尚处于起步阶段的网站。多年来,各种版本不断演变,有时出于偶然,有时出于故意(注入幽默等)。
它来自哪里?
与流行的观点相反,Lorem Ipsum不是简单的随机文本。它起源于公元前45年的一段古典拉丁文学,距今已有2000多年的历史。弗吉尼亚州汉普顿悉尼学院的拉丁语教授理查德·麦克林托克(Richard McClintock)从《洛伦·伊普斯姆》(Lorem Ipsum)一段中查找了一个更为晦涩的拉丁语单词,即“Concertetur”,并查阅了古典文学中对该词的引用,发现了该词无可置疑的来源。Lorem Ipsum来自西塞罗于公元前45年所著《德菲尼布斯·博诺勒姆和马洛勒姆》(善与恶的极端)的第1.10.32节和第1.10.33节。这本书是一本关于伦理学理论的论文,在文艺复兴时期非常流行。Lorem Ipsum的第一行“Lorem Ipsum dolor sit amet..”来自第1.10.32节中的一行。
以下是自1500年代以来使用的Lorem Ipsum的标准块,供感兴趣的人参考。西塞罗的“de Finibus Bonorum et Malorum”中的第1.10.32节和第1.10.33节也以其原始形式复制,并附有H.Rackham 1914年翻译的英文版本。
我在哪里可以买到?
《洛雷姆·伊普苏姆》中有很多不同的段落,但大多数都经历了某种形式的变化,比如注入幽默,或者随机的词语,这些词语看起来甚至一点都不可信。如果你要使用LROM乱数假文,你需要确保在文本中间没有任何隐藏的尴尬。互联网上的所有Lorem Ipsum生成器都倾向于在必要时重复预定义的块,这使得它成为互联网上第一个真正的生成器。它使用了一本包含200多个拉丁单词的字典,并结合了一些典型的句子结构,生成了看起来合理的Lorem Ipsum。因此,生成的知识总是没有重复、注入的幽默或非特征词等

我建议不要固定标题
而是提供滚动到正文
,因为型号
弹出窗口
固定位置
,所以滚动正文更好。检查代码段

$(函数(){
常量OpenModels=[];
$('.modal按钮')。单击(e=>{
e、 预防默认值();
$(e.target)。最近('.modal')。添加('body')。添加类('open');
openModals.push($($(e.target.attr('href')).show());
});
$(窗口)。添加('.close')。单击(e=>{
e、 停止传播();
if($(e.target).is('.model.close')){
const closing=openModals.pop().addClass('modal-content-active');
设置超时(()=>{
closing.hide().removeClass('modal-content-active')
}, 400);
如果(openModals.length>0){
openModals[openModals.length-1].removeClass('open');
}else$('body').removeClass('open');
}
$('.modal body').scrollTop(0);
});
});
@导入url('https://fonts.googleapis.com/css?family=Quicksand&display=swap');
/*模态(背景)*/
.模态体{
最大高度:计算(100vh-95px);
溢出y:滚动;
}
.莫代尔{
框大小:边框框;
字体系列:“流沙”,无衬线;
显示:无;
/*默认情况下隐藏*/
位置:固定;
/*原地不动*/
z指数:1;
/*坐在上面*/
垫面:3.125rem;
/*盒子的位置*/
左:0;
排名:0;
宽度:100%;
/*全宽*/
身高:100%;
/*全高*/
溢出:自动;
/*如果需要,启用滚动*/
背景色:rgb(0,0,0);
/*退色*/
背景色:rgba(0,0,0,0.4);
/*黑色w/不透明度*/
}
/*模态内容*/
.模态内容{
颜色:白色;
位置:相对位置;
背景色:#171B20;
保证金:自动;
填充:0;
边框:0.0625rem实心#888;
宽度:90%;
盒子阴影:0.25雷姆0.5雷姆0 rgba(0,0,0,0.2),0.375雷姆1.25雷姆0 rgba(0,0,0,0.19);
-webkit动画名称:animatetop;
-webkit动画持续时间:0.4s;
动画名称:animatetop;
动画持续时间:0.4s;
最大高度:计算(100vh-52px);
}
/*添加动画*/
@-webkit关键帧动画顶点{
从{
顶部:-300px;
不透明度:0;
}
到{
排名:0;
不透明度:1;
}
}
@关键帧动画顶点{
从{
顶部:-300px;
不透明度:0;
}
到{
排名:0;
不透明度:1;
}
}
@-webkit密钥
@import url('https://fonts.googleapis.com/css?family=Quicksand&display=swap');

/* The Modal (background) */

.modal {
  box-sizing: border-box;
  font-family: 'Quicksand', sans-serif;
  display: none;
  /* Hidden by default */
  position: fixed;
  /* Stay in place */
  z-index: 1;
  /* Sit on top */
  padding-top: 3.125rem;
  /* Location of the box */
  left: 0;
  top: 0;
  width: 100%;
  /* Full width */
  height: 100%;
  /* Full height */
  overflow: auto;
  /* Enable scroll if needed */
  background-color: rgb(0, 0, 0);
  /* Fallback color */
  background-color: rgba(0, 0, 0, 0.4);
  /* Black w/ opacity */
}


/* Modal Content */

.modal-content {
  color: white;
  position: relative;
  background-color: #171B20;
  margin: auto;
  padding: 0;
  border: 0.0625rem solid #888;
  width: 90%;
  box-shadow: 0 0.25rem 0.5rem 0 rgba(0, 0, 0, 0.2), 0 0.375rem 1.25rem 0 rgba(0, 0, 0, 0.19);
  -webkit-animation-name: animatetop;
  -webkit-animation-duration: 0.4s;
  animation-name: animatetop;
  animation-duration: 0.4s;
}


/* Add Animation */

@-webkit-keyframes animatetop {
  from {
    top: -300px;
    opacity: 0;
  }
  to {
    top: 0;
    opacity: 1;
  }
}

@keyframes animatetop {
  from {
    top: -300px;
    opacity: 0;
  }
  to {
    top: 0;
    opacity: 1;
  }
}

@-webkit-keyframes animateBottom {
  from {
    top: 0px;
    opacity: 1;
  }
  to {
    top: 500px;
    opacity: 0;
  }
}

@keyframes animateBottom {
  from {
    top: 0px;
    opacity: 1;
  }
  to {
    top: 300px;
    opacity: 0;
  }
}

.modal-content-active {
  -webkit-animation-name: animateBottom;
  -webkit-animation-duration: 0.4s;
  animation-name: animateBottom;
  animation-duration: 0.4s;
}


/* The Close Button */

.close {
  color: #F0B823;
  float: right;
  font-size: 2.6rem;
  font-weight: bold;
  position: absolute;
  right: 0.25rem;
  top: -0.25rem;
}

.close:hover,
.close:focus {
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}

.modal-header {
  padding: 0.125rem 1rem;
  background-color: #171B20;
  color: #F0B823;
}

.modal-body {}

.modal-button {
  font-family: 'Quicksand', sans-serif;
  background-color: #171B20;
  border: none;
  color: white;
  padding: 0.248em 0.496em;
  text-align: left;
  text-decoration: none;
  display: inline-block;
  font-size: 1.750rem;
  margin: 0.124em 0.062em;
  -webkit-transition-duration: 0;
  /* Safari */
  transition-duration: 0;
  cursor: pointer;
  width: auto;
}

.modal-button:hover {
  background-color: #171B20;
  color: #F0B823;
}

.pic {
  margin: auto;
  display: block;
  height: auto;
  width: 50vh;
}

.headertext {
  font-family: 'Quicksand', sans-serif;
  display: block;
  text-align: center;
  font-size: 2rem;
}

.bodytext {
  font-size: 1.125rem;
  font-family: 'Quicksand', sans-serif;
  display: block;
  padding: 0.625em 0.9375em;
  line-height: 2rem;
}

p {
  display: block;
  margin: 0;
  padding: 0;
}

.open {
  overflow: hidden;
}

.open>* {
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);
}

.modal {
  -webkit-filter: blur(0px);
  -moz-filter: blur(0px);
  -o-filter: blur(0px);
  -ms-filter: blur(0px);
  filter: blur(0px);
}

.modal .open {
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

.bold {
  display: inline-block;
  font-weight: 900;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<!-- Trigger/Open The Modal -->
<a href="#myModal1" class="modal-button">• Click Me</a>

<!-- The Modal -->
<div id="myModal1" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">×</span>
      <div class="headertext">
             Modal Header
      </div>
    </div>
    <div class="modal-body">
      <img class="pic" src="https://drive.google.com/thumbnail?id=108ZLeoIfNkKODfRbLuPWpmXRl0gH9qkD">
      <div class="bodytext">
           What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

Where can I get some?
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc
      </div>
    </div>
  </div>
</div>
.modal-body {
        overflow-y:scroll;        
        position: absolute;
        height : 450px;
}

.modal-header {
  padding: 0.125rem 1rem;
  background-color: #171B20;
  color: #F0B823;
  z-index : 1;

}