jQuery模拟原生态App上拉刷新下拉加载效果
用手机查看演示效果会更好
JavaScript Code
- <script>
- var holdPosition = 0;
- var mySwiper = new Swiper('.swiper-container',{
- slidesPerView:'auto',
- mode:'vertical',
- watchActiveIndex: true,
- onTouchStart: function() {
- holdPosition = 0;
- },
- onResistanceBefore: function(s, pos){
- holdPosition = pos;
- },
- onTouchEnd: function(){
- if (holdPosition>100) {
- mySwiper.setWrapperTranslate(0,100,0)
- mySwiper.params.onlyExternal=true
- $('.preloader').addClass('visible');
- loadNewSlides();
- }
- }
- })
- var slideNumber = 0;
- function loadNewSlides(){
- setTimeout(function(){
- //Prepend new slide
- var colors = ['red','blue','green','orange','pink'];
- var color = colors[Math.floor(Math.random()*colors.length)];
- mySwiper.prependSlide('<div class="title">freejs.net '+slideNumber+'</div>', 'swiper-slide '+color+'-slide');
- //Release interactions and set wrapper
- mySwiper.setWrapperTranslate(0,0,0)
- mySwiper.params.onlyExternal=false;
- //Update active slide
- mySwiper.updateActiveSlide(0)
- //Hide loader
- $('.preloader').removeClass('visible');
- },1000)
- slideNumber++;
- }
- </script>
原文地址:http://www.freejs.net/article_jquerywenzi_663.html