我有这个jquery页面,我使用Swiper库通过垂直滑动来显示我的内容。我想通过单击侧面板上的任何链接转到特定的幻灯片。当我向上或向下滑动时,没有页面滚动,但是当我单击从面板转到特定链接时,页面向下滚动,我可以&#39 ; t从那张幻灯片上滑下来。
有没有办法在不滚动页面并保持标题和面板固定的情况下仅显示所需的幻灯片? 这是我的代码 -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Swiper demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<!-- Link Swiper's CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/css/swiper.min.css" rel="stylesheet"/>
<!--jquery mobile links -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!-- Demo styles -->
<style>
html, body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color:#000;
margin: 0;
padding: 0;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
</style>
</head>
<body>
<div data-role="panel" id="mypanel" data-position="left" data-display="overlay" data-theme="a">
<ul data-role="listview">
<li><a href = "#link1">Slide 1</a></li>
<li><a href = "#link2">Slide 2</a></li>
<li><a href = '#link3'>Slide 3</a></li>
</ul>
</div>
<div data-role="header" data-theme="b" data-position="fixed" data-id="header">
<h1>Home</h1>
<a href="#mypanel" class="ui-btn ui-btn-left ui-btn-icon-notext ui-icon-grid ui-corner-all"></a>
</div>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" id="link1">Slide 1</div>
<div class="swiper-slide" id="link2">Slide 2</div>
<div class="swiper-slide" id = 'link3'>Slide 3</div>
</div>
</div>
<!-- Swiper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/js/swiper.min.js"></script>
<!-- Initialize Swiper -->
<script>
var swiper = new Swiper('.swiper-container',{
direction : 'vertical',
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
window.location.hash = target;
});
});
</script>
</body>
</html>
&#13;
答案 0 :(得分:0)
您的固定标头可能无法正常工作,因为您的内容未包含在JQuery移动网页元素中。您可以尝试在JQuery移动页面中包装面板,标题和swiper div,例如 -
<body>
<div data-role="page">
<div data-role="panel" id="mypanel" data-position="left" data-display="overlay" data-theme="a">
<!--panel content-->
</div>
<div data-role="header" data-position="fixed">
<h1>Fixed header</h1>
</div>
<div role="main">
<!-- Put your swiper here -->
</div>
<div data-role="footer" data-position="fixed">
<h1>Fixed footer</h1>
</div>
</div>
</body>
您可以在此处查看有关固定标题的JQM文档:JQM Fixed header 和固定面板:JQM fixed panels