gpt4 book ai didi

javascript - AngularJS- ionic : create a swipeable horizonatlview which will update vertical view

转载 作者:太空狗 更新时间:2023-10-29 13:29:32 25 4
gpt4 key购买 nike

我想使用 angularjs 和 ionic 创建适用于 Android 和 iOS 的 UI。 View 如下: enter image description here

说明:在这个 View 中,我想要一个包含日期的水平条(当前显示 1 到 8 个日期,但它可以从每月的第 1 天到每月的最后一天滑动)。该条可左右滑动。每天都会有一些数据显示在垂直 ListView 中。当用户同时在水平条上向左或向右滑动时,垂直数据将更新。垂直 ListView 将仅显示水平条中显示的日期的数据。

我不确定我该怎么做。任何指针,例如库/示例代码等将不胜感激。

谢谢

最佳答案

我会推荐 swiper ,我以前用过它,我发现它简单易用:http://idangero.us/swiper/ , http://idangero.us/swiper/get-started/

文档:http://idangero.us/swiper/api/

Swiper is also a default slider component in Ionic Framework

快速概览:

你可以配置它显示x一次滑动,中间的总是有 swiper-slide-active类(class),你有事件slideChangeswiper-slide-active 时被触发被改变了,你可以输入你想要的任何函数(也许是一个 ajax 函数来获取当天的数据)它只是被解雇了一点,所以你需要把它包装在 setTimeout 中。的 1ms

我根据你的布局做了一个基本的例子,这里有一个你可以玩的 fiddle ,并根据你的需要改变它:

https://jsfiddle.net/o9u0qenk/15/ (每周更新) https://jsfiddle.net/o9u0qenk/22/ (实时更新)

编辑

显示7天范围内的数据,centeredSlides: true被删除所以swiper-slide-active成为左边的第一张幻灯片,所以这是你的 startDate , 加 6 得到 endDate

编辑2

要实时跟踪天数,您可以使用事件 sliderMove检测 slider 是否在移动并在它移动时做一些事情,你可以存储 offsetLeft Array 中的每张幻灯片并在用户滑动并将值与当前 offset 进行比较时循环遍历它刷卡器,然后 break当比赛不继续通过 loop

编辑片段:

var content = document.getElementById('content');

var currenOffset; // swiper's offset
var childOffset; // slide's offset

var startIndex;
var endIndex;

var slides = document.getElementsByClassName('swiper-slide');
var slidesOffsets = [];

var swiper = new Swiper('.swiper-container', {
slidesPerView: 7,
spaceBetween: 10,
on: {
init: function () {
setTimeout(function(){
var startDay = document.getElementsByClassName('swiper-slide-active')[0].innerHTML;
var endDay = parseInt(startDay) + 6 ;
content.innerHTML = '<div> Showing data for days ' + startDay + ' to ' + endDay + '</div>';
}, 1);
}
}
});

swiper.on('slideChange', function () {
setTimeout(function(){
var startDay = document.getElementsByClassName('swiper-slide-active')[0].innerHTML;
var endDay = parseInt(startDay) + 6 ;
content.innerHTML = '<div> Showing data for days ' + startDay + ' to ' + endDay + '</div>';
}, 1);
});


for(var i =0; i < slides.length; i++){
slidesOffsets.push((slides[i].offsetLeft * -1) + 10);
}

swiper.on('sliderMove', function(e){
currentOffset = this.translate;

for(var i=0; i<slides.length; i++){
if( slidesOffsets[i] <= currentOffset){
startIndex = i ;
break;
}
}

endIndex = startIndex + 6;
content.innerHTML = '<div> Showing data for days ' + startIndex + ' to ' + endIndex + '</div>';
});
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: 80px;
}
.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;
}

#content{
width: 100%;
height: calc(100% - 80px);
}
#content div{
margin: auto;
text-align: center;
padding-top: 50px;
font-size: 30px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/css/swiper.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.2.0/js/swiper.min.js"></script>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">1</div>
<div class="swiper-slide">2</div>
<div class="swiper-slide">3</div>
<div class="swiper-slide">4</div>
<div class="swiper-slide">5</div>
<div class="swiper-slide">6</div>
<div class="swiper-slide">7</div>
<div class="swiper-slide">8</div>
<div class="swiper-slide">9</div>
<div class="swiper-slide">10</div>
<div class="swiper-slide">11</div>
<div class="swiper-slide">12</div>
<div class="swiper-slide">13</div>
<div class="swiper-slide">14</div>
<div class="swiper-slide">15</div>
<div class="swiper-slide">16</div>
<div class="swiper-slide">17</div>
<div class="swiper-slide">18</div>
<div class="swiper-slide">19</div>
<div class="swiper-slide">20</div>
<div class="swiper-slide">21</div>
<div class="swiper-slide">22</div>
<div class="swiper-slide">23</div>
<div class="swiper-slide">24</div>
<div class="swiper-slide">25</div>
<div class="swiper-slide">26</div>
<div class="swiper-slide">27</div>
<div class="swiper-slide">28</div>
<div class="swiper-slide">29</div>
<div class="swiper-slide">30</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>

<div id="content">

</div>

我希望这对您有所帮助,祝您好运。

最终预期结果:https://jsfiddle.net/o9u0qenk/40/

关于javascript - AngularJS- ionic : create a swipeable horizonatlview which will update vertical view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49290138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com