使用链接滚动文章而不关闭模态

时间:2016-12-17 02:50:06

标签: html css

我正在尝试这样做,以便当您点击链接时,它会向下滚动到下一部分。它似乎滚动得很好,但是当我点击链接时它总是关闭。有什么方法可以解决这个问题吗?

.modalDialog {
  position: fixed;
  width: 100%;
  height: 100%;
  font-family: 'gothic' !important;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 99999;
  opacity: 0;
  -webkit-transition: opacity 400ms ease-in;
  -moz-transition: opacity 400ms ease-in;
  transition: opacity 400ms ease-in;
  pointer-events: none;
}

.modalDialog:target {
  opacity: 1;
  pointer-events: auto;
}

.modalDialog > div {
  width: 90%;
  height: 600px;
  position: relative;
  top: 12px;
  margin: auto;
  padding: 5px 20px 13px 20px;
  border-radius: 10px;
  border: solid #2E51A2 2px;
  background-color: #1d1d1d;
  color: #999;
}

.close {
  background: #2E51A2;
  color: #fff;
  line-height: 25px;
  position: absolute;
  right: -12px;
  text-align: center;
  top: -10px;
  width: 24px;
  text-decoration: none;
  font-weight: bold;
  -webkit-border-radius: 12px;
  -moz-border-radius: 12px;
  border-radius: 12px;
  -moz-box-shadow: 1px 1px 3px #000;
  -webkit-box-shadow: 1px 1px 3px #000;
  box-shadow: 1px 1px 3px #000;
}

.close:hover {
  color: #000;
}

#content {
  width: 60%;
  float: right;
  font-family: 'gothic' !important;
  overflow-y: hidden;
  overflow-x: hidden;
  height: 396px;
  border: 2px solid #2E51A2;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  border-top-right-radius: 5px;
}

#description {
  width: 100%;
  height: 396px;
  overflow-y: hidden;
  overflow-x: hidden;
}

#contentGuide {
  width: 100%;
  height: 396px;
  overflow-y: scroll;
  overflow-x: hidden;
}

.contentLink {
  display: block;
  width: 200px;
  height: 50px;
  border-left: 2px solid #2E51A2;
  border-right: 2px solid #2E51A2;
  border-top: 2px solid #2E51A2;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  background-color: #1d1d1d;
  color: #999;
  position: relative;
  top: 2px;
  right: 4px;
  font-size: 16pt;
  line-height: 50px;
  text-decoration: none;
  text-align: center;
  float: left;
}

.contentLink:active {
  background-color: #2E51A2;
}

#linkContain {
  width: 60%;
  height: 54px;
  float: right;
}
<a href="#openModal">Open Modal</a>

<div id="openModal" class="modalDialog">
  <div> <a href="#close" title="Close" class="close">X</a>
    <div id="linkContain">
      <a href="#description" class="contentLink">About</a><a href="#contentGuide" class="contentLink">Content Guide</a>
    </div>
    <article id="content">
      <article id="description">
        Content 1
      </article>

      <article id="contentGuide">
        Content 2
      </article>
    </article>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

尝试使用此工作代码段,这就是您需要的内容

&#13;
&#13;
$(document).ready(function(){
  activaTab('aaa');
});

function activaTab(tab){
  $('.nav-tabs a[href="#' + tab + '"]').tab('show');
};
&#13;
.modalDialog {
	position: fixed;
	width: 100%;
	height: 100%;
	font-family: 'gothic' !important;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.8);
	z-index: 99999;
	opacity:0;
	-webkit-transition: opacity 400ms ease-in;
	-moz-transition: opacity 400ms ease-in;
	transition: opacity 400ms ease-in;
	pointer-events: none;
}

.modalDialog:target {
	opacity:1;
	pointer-events: auto;
}

.modalDialog > div {
	width: 90%;
	height: 600px;
	position: relative;
	top: 12px;
	margin: auto;
	padding: 5px 20px 13px 20px;
	border-radius: 10px;
	border: solid #2E51A2 2px;
	background-color: #1d1d1d;
	color: #999;
}

.close {
	background: #2E51A2;
	color: #fff;
	line-height: 25px;
	position: absolute;
	right: -12px;
	text-align: center;
	top: -10px;
	width: 24px;
	text-decoration: none;
	font-weight: bold;
	-webkit-border-radius: 12px;
	-moz-border-radius: 12px;
	border-radius: 12px;
	-moz-box-shadow: 1px 1px 3px #000;
	-webkit-box-shadow: 1px 1px 3px #000;
	box-shadow: 1px 1px 3px #000;
}

.close:hover {
	color: #000;
}

#tabs {
	width: 60%;
	float: right;
	font-family: 'gothic' !important;
	overflow-y: hidden;
	overflow-x: hidden;
	height: 396px;
	border: 2px solid #2E51A2;
	border-bottom-left-radius: 5px;
	border-bottom-right-radius: 5px;
	border-top-right-radius: 5px;
}

#description {
	width: 100%;
	height: 396px;
	overflow-y: hidden;
	overflow-x: hidden;
}

#contentGuide {
	width: 100%;
	height: 396px;
	overflow-y: scroll;
	overflow-x: hidden;
}

.contentLink {
	display: block;
	width: 200px;
	height: 50px;
	border-left: 2px solid #2E51A2;
	border-right: 2px solid #2E51A2;
	border-top: 2px solid #2E51A2;
	border-top-left-radius: 5px;
	border-top-right-radius: 5px;
	background-color: #1d1d1d;
	color: #999;
	position: relative;
	top: 2px;
	right: 4px;
	font-size: 16pt;
	line-height: 50px;
	text-decoration: none;
	text-align: center;
	float: left;
}

.contentLink:active {
	background-color: #2E51A2;
}

#linkContain {
	width: 60%;
	height: 54px;
	float: right;
}
&#13;
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>

<body>

<a href="#openModal">Open Modal</a>
	
<div id="openModal" class="modalDialog">
	<div>	<a href="#close" title="Close" class="close">X</a>
		<div id="linkContain">
			<a href="#description" class="contentLink" data-toggle="tab">About</a>
            <a href="#contentGuide" class="contentLink" data-toggle="tab">Content Guide</a>
		</div>
		<article class="tab-content" id="tabs">
			<article class="tab-pane" id="description">
				Content 1
			</article>
				
			<article class="tab-pane" id="contentGuide">
				Content 2
			</article>
		</article>
        </div>
</div>


<!-- /.outer --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>
</html>
&#13;
&#13;
&#13;