GVKun编程网logo

iscroll.js实现简单分页(js实现分页功能)

13

以上就是给各位分享iscroll.js实现简单分页,其中也会对js实现分页功能进行解释,同时本文还将给你拓展AndroidGridviewOnScrollListenerScrollUp和Scroll

以上就是给各位分享iscroll.js实现简单分页,其中也会对js实现分页功能进行解释,同时本文还将给你拓展Android Gridview OnScrollListener ScrollUp和ScrollDown事件、asp.net实现简单分页实例、better-scroll 实现简单的轮播 无缝滚动~、Django实现简单分页功能的方法详解等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

iscroll.js实现简单分页(js实现分页功能)

iscroll.js实现简单分页(js实现分页功能)

前端使用ajax请求后台数据,参数有页数,

 

上拉加载:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>html5+css3实现上拉和下拉刷新</title>

<script type="text/javascript" src="http://statics.webkfa.com/js/iscroll.js"></script>

<script type="text/javascript">

var myScroll,
	pullDownEl, pullDownOffset,
	pullUpEl, pullUpOffset,
	generatedCount = 0;

function pullDownAction () {
	setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
		var el, li, i;
		el = document.getElementById(''thelist'');

		for (i=0; i<3; i++) {
			li = document.createElement(''li'');
			li.innerText = ''Generated row '' + (++generatedCount);
			el.insertBefore(li, el.childNodes[0]);
		}
		
		myScroll.refresh();		// Remember to refresh when contents are loaded (ie: on ajax completion)
	}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
}

function pullUpAction () {
	setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
		var el, li, i;
		el = document.getElementById(''thelist'');

		for (i=0; i<3; i++) {
			li = document.createElement(''li'');
			li.innerText = ''Generated row '' + (++generatedCount);
			el.appendChild(li, el.childNodes[0]);
		}
		
		myScroll.refresh();		// Remember to refresh when contents are loaded (ie: on ajax completion)
	}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
}

function loaded() {
	pullDownEl = document.getElementById(''pullDown'');
	pullDownOffset = pullDownEl.offsetHeight;
	pullUpEl = document.getElementById(''pullUp'');	
	pullUpOffset = pullUpEl.offsetHeight;
	
	myScroll = new iScroll(''wrapper'', {
		useTransition: true,
		topOffset: pullDownOffset,
		onRefresh: function () {
			if (pullDownEl.className.match(''loading'')) {
				pullDownEl.className = '''';
				pullDownEl.querySelector(''.pullDownLabel'').innerHTML = ''Pull down to refresh...'';
			} else if (pullUpEl.className.match(''loading'')) {
				pullUpEl.className = '''';
				pullUpEl.querySelector(''.pullUpLabel'').innerHTML = ''Pull up to load more...'';
			}
		},
		onScrollMove: function () {
			if (this.y > 5 && !pullDownEl.className.match(''flip'')) {
				pullDownEl.className = ''flip'';
				pullDownEl.querySelector(''.pullDownLabel'').innerHTML = ''Release to refresh...'';
				this.minScrollY = 0;
			} else if (this.y < 5 && pullDownEl.className.match(''flip'')) {
				pullDownEl.className = '''';
				pullDownEl.querySelector(''.pullDownLabel'').innerHTML = ''Pull down to refresh...'';
				this.minScrollY = -pullDownOffset;
			} else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match(''flip'')) {
				pullUpEl.className = ''flip'';
				pullUpEl.querySelector(''.pullUpLabel'').innerHTML = ''Release to refresh...'';
				this.maxScrollY = this.maxScrollY;
			} else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match(''flip'')) {
				pullUpEl.className = '''';
				pullUpEl.querySelector(''.pullUpLabel'').innerHTML = ''Pull up to load more...'';
				this.maxScrollY = pullUpOffset;
			}
		},
		onScrollEnd: function () {
			if (pullDownEl.className.match(''flip'')) {
				pullDownEl.className = ''loading'';
				pullDownEl.querySelector(''.pullDownLabel'').innerHTML = ''Loading...'';				
				pullDownAction();	// Execute custom function (ajax call?)
			} else if (pullUpEl.className.match(''flip'')) {
				pullUpEl.className = ''loading'';
				pullUpEl.querySelector(''.pullUpLabel'').innerHTML = ''Loading...'';				
				pullUpAction();	// Execute custom function (ajax call?)
			}
		}
	});
	
	setTimeout(function () { document.getElementById(''wrapper'').style.left = ''0''; }, 800);
}

document.addEventListener(''touchmove'', function (e) { e.preventDefault(); }, false);

document.addEventListener(''DOMContentLoaded'', function () { setTimeout(loaded, 200); }, false);
</script>

<style type="text/css" media="all">
body,ul,li {
	padding:0;
	margin:0;
	border:0;
}

body {
	font-size:12px;
	-webkit-user-select:none;
    -webkit-text-size-adjust:none;
	font-family:helvetica;
}

#header {
	position:absolute; z-index:2;
	top:0; left:0;
	width:100%;
	height:45px;
	line-height:45px;
	background-color:#d51875;
	background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #fe96c9), color-stop(0.05, #d51875), color-stop(1, #7b0a2e));
	background-image:-moz-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
	background-image:-o-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
	padding:0;
	color:#eee;
	font-size:20px;
	text-align:center;
}

#header a {
	color:#f3f3f3;
	text-decoration:none;
	font-weight:bold;
	text-shadow:0 -1px 0 rgba(0,0,0,0.5);
}

#footer {
	position:absolute; z-index:2;
	bottom:0; left:0;
	width:100%;
	height:48px;
	background-color:#222;
	background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #999), color-stop(0.02, #666), color-stop(1, #222));
	background-image:-moz-linear-gradient(top, #999, #666 2%, #222);
	background-image:-o-linear-gradient(top, #999, #666 2%, #222);
	padding:0;
	border-top:1px solid #444;
}

#wrapper {
	position:absolute; z-index:1;
	top:45px; bottom:48px; left:-9999px;
	width:100%;
	background:#aaa;
	overflow:auto;
}

#scroller {
	position:absolute; z-index:1;
/*	-webkit-touch-callout:none;*/
	-webkit-tap-highlight-color:rgba(0,0,0,0);
	width:100%;
	padding:0;
}

#scroller ul {
	list-style:none;
	padding:0;
	margin:0;
	width:100%;
	text-align:left;
}

#scroller li {
	padding:0 10px;
	height:40px;
	line-height:40px;
	border-bottom:1px solid #ccc;
	border-top:1px solid #fff;
	background-color:#fafafa;
	font-size:14px;
}

#myFrame {
	position:absolute;
	top:0; left:0;
}



/**
 *
 * Pull down styles
 *
 */
#pullDown, #pullUp {
	background:#fff;
	height:40px;
	line-height:40px;
	padding:5px 10px;
	border-bottom:1px solid #ccc;
	font-weight:bold;
	font-size:14px;
	color:#888;
}
#pullDown .pullDownIcon, #pullUp .pullUpIcon  {
	display:block; float:left;
	width:40px; height:40px;
	background:url(http://statics.webkfa.com/img/pull-icon@2x.png) 0 0 no-repeat;
	-webkit-background-size:40px 80px; background-size:40px 80px;
	-webkit-transition-property:-webkit-transform;
	-webkit-transition-duration:250ms;	
}
#pullDown .pullDownIcon {
	-webkit-transform:rotate(0deg) translateZ(0);
}
#pullUp .pullUpIcon  {
	-webkit-transform:rotate(-180deg) translateZ(0);
}

#pullDown.flip .pullDownIcon {
	-webkit-transform:rotate(-180deg) translateZ(0);
}

#pullUp.flip .pullUpIcon {
	-webkit-transform:rotate(0deg) translateZ(0);
}

#pullDown.loading .pullDownIcon, #pullUp.loading .pullUpIcon {
	background-position:0 100%;
	-webkit-transform:rotate(0deg) translateZ(0);
	-webkit-transition-duration:0ms;

	-webkit-animation-name:loading;
	-webkit-animation-duration:2s;
	-webkit-animation-iteration-count:infinite;
	-webkit-animation-timing-function:linear;
}

@-webkit-keyframes loading {
	from { -webkit-transform:rotate(0deg) translateZ(0); }
	to { -webkit-transform:rotate(360deg) translateZ(0); }
}

</style>
</head>
<body>

<div id="header"><a href="http://cubiq.org/iscroll">iScroll</a></div>
<div id="wrapper">
	<div id="scroller">
		<div id="pullDown">
			<span></span><span>Pull down to refresh...</span>
		</div>

		<ul id="thelist">
			<li>Pretty row 1</li>
			<li>Pretty row 2</li>
			<li>Pretty row 3</li>
			<li>Pretty row 4</li>
			<li>Pretty row 5</li>
			<li>Pretty row 6</li>
			<li>Pretty row 7</li>
			<li>Pretty row 8</li>
			<li>Pretty row 9</li>
			<li>Pretty row 10</li>
			<li>Pretty row 11</li>
			<li>Pretty row 12</li>
			<li>Pretty row 13</li>
			<li>Pretty row 14</li>
			<li>Pretty row 15</li>
			<li>Pretty row 16</li>
			<li>Pretty row 17</li>
			<li>Pretty row 18</li>
			<li>Pretty row 19</li>
			<li>Pretty row 20</li>
			<li>Pretty row 21</li>
			<li>Pretty row 22</li>
			<li>Pretty row 23</li>
			<li>Pretty row 24</li>
			<li>Pretty row 25</li>
			<li>Pretty row 26</li>
			<li>Pretty row 27</li>
			<li>Pretty row 28</li>
			<li>Pretty row 29</li>
			<li>Pretty row 30</li>
			<li>Pretty row 31</li>
			<li>Pretty row 32</li>
			<li>Pretty row 33</li>
			<li>Pretty row 34</li>
			<li>Pretty row 35</li>
			<li>Pretty row 36</li>
			<li>Pretty row 37</li>
			<li>Pretty row 38</li>
			<li>Pretty row 39</li>
			<li>Pretty row 40</li>
		</ul>
		<div id="pullUp">
			<span></span><span>Pull up to refresh...</span>
		</div>
	</div>
</div>
<div id="footer"></div>

</body>
</html>

 

Android Gridview OnScrollListener ScrollUp和ScrollDown事件

Android Gridview OnScrollListener ScrollUp和ScrollDown事件

我有gridview,我需要做两件事:

当我向下滚动时,我想找到最后一个可见位置,例如int index = GridView.getLastVisiblePosition();

当我向上滚动时,我想找到第一个可见位置,例如int index = GridView.getFirstVisiblePosition();

我知道我可以使用以下代码,但我不确定如何以及在何处为ScrollUp和ScrollDown编写代码.请帮我.我是Android新手.

private OnScrollListener onAnsweRSScrolled = new OnScrollListener() {

    @Override
    public void onScrollStateChanged(AbsListView view,int scrollState) {
    }
}

解决方法

在你的活动中创建全局变量myLastVisiblePos,并为每个FirstVisiblePosition保存,当onScroll事件检查当前FirstVisiblePosition时保存的FirstVisiblePosition如果greate比上次保存的FirstVisiblePosition那么scrollUp如果小则滚动:
int myLastVisiblePos;// global variable of activity

//save first value when you create GridView
GridView gridView = (GridView) gv.findViewById(R.id.grid_view);
myLastVisiblePos = gridView.getFirstVisiblePosition();

gridView.setonScrollListener( new OnScrollListener() {
    @Override
    public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount) {
            int currentFirstVisPos = view.getFirstVisiblePosition();
            if(currentFirstVisPos > myLastVisiblePos) {
                //scroll down
            }
            if(currentFirstVisPos < myLastVisiblePos) {
                //scroll up
            }
            myLastVisiblePos = currentFirstVisPos;
    }
});

asp.net实现简单分页实例

asp.net实现简单分页实例

本文实例讲述了asp.net实现简单分页的方法。分享给大家供大家参考。

具体实现方法如下:

复制代码 代码如下:
/// <summary>
/// 分页内容
/// </summary>
/// <param name="size">页面大小</param>
/// <param name="count">页面数量</param>
/// <param name="currendIndex">当前页</param>
/// <param name="pattern">url模式:demo.aspx?page={0}</param>
/// <param name="target">窗口模式</param>
/// <returns></returns>
public static string get_pagenation(int size,
                                    int count,
                                    int currendIndex,
                                    string pattern,
                                    string target)
{
    //1>打开窗口目标
    target = string.IsNullOrEmpty(target) ? "_top" : target;
    //2>总页数
    int pageCount = count / size;
    pageCount = pageCount * size == count ? pageCount : pageCount + 1;
    //3>分页内容
    StringBuilder strHtml = new StringBuilder();
    strHtml.Append("<spanpagenation''>");
 
    #region 首部处理
    if (currendIndex > 1)
    {
        strHtml.AppendFormat("<a href=''1'' target=''{0}''>[首页]</a>", target);
        strHtml.AppendFormat("<a href=''{0}'' target=''{1}''>[上一页]</a>", string.Format(pattern, currendIndex - 1), target);
    }
    else
    {
        strHtml.Append("<spandisabled''>[首页]</span>&nbsp;&nbsp;<spandisabled''>[上一页]</span>");
    }
    #endregion
 
    #region 中间部分
    int i = 1;
 
    int right = (currendIndex + 4) > pageCount ? pageCount : currendIndex + 4;
    if (currendIndex > 6)
    {
        i = currendIndex - 5;
    }
    else
    {
        right = pageCount >= 10 ? 10 : pageCount;
    }
    for (; i <= right; i++)
    {
        if (i == currendIndex)
        {
            strHtml.AppendFormat("<fontcurrent''>{0}</font>", i);
            strHtml.AppendLine();
            continue;
        }
        strHtml.AppendFormat("<a href=''{0}'' target=''{1}''>[{2}]</a>", string.Format(pattern, i), target, i);
        strHtml.AppendLine();
    }
    #endregion
 
    #region 尾部处理
    if (currendIndex == pageCount)
    {
        strHtml.Append("<spandisabled''>[下一页]</span><spandisabled''>[末页]</span>");
        strHtml.AppendFormat("总共({0})页", pageCount);
    }
    else
    {
        strHtml.AppendFormat("<a href=''{0}'' target=''{1}''>[下一页]</a>", string.Format(pattern, currendIndex + 1), target);
        strHtml.AppendFormat("<a href=''{0}'' target=''{1}''>[末页]</a>", string.Format(pattern, pageCount), target);
        strHtml.AppendFormat("&nbsp;&nbsp;<label>总共({0})页</label>", pageCount);
    }
    #endregion
 
    strHtml.Append("</span>");
 
    return strHtml.ToString();
}

希望本文所述对大家的asp.net程序设计有所帮助。

您可能感兴趣的文章:
  • asp.net利用后台实现直接生成html分页的方法
  • ASP.NET无刷新分页简单实现
  • Asp.Net之JS生成分页条的方法

better-scroll 实现简单的轮播 无缝滚动~

better-scroll 实现简单的轮播 无缝滚动~

代码如下:


<template> <div class="slide_box"> <div class="slide" ref="slider"> <div class="slide-group" ref=''slideGroup''> <slot> </slot> </div> <div class="dots"> <span class="dot" :class="{dotActive: (currentPageIndex) === index }" v-for="(item, index) in dots">{{index+1}}</span> </div> </div> </div> </template> <script> import BScroll from ''better-scroll''; export default { name:"betterScroll", props: { loop: { type: Boolean, default: true, }, autoPlay: { type: Boolean, default: true, }, interval: { type: Number, default: 1000 } }, data() { return { dots:[], currentPageIndex:0 } }, mounted() { this.setSliderWidth(); //设置轮播图的宽度 setTimeout(()=>{ this._initDots(); this.init(); if(this.autoPlay) { this.play(); } },20) }, destroyed() { clearTimeout(this.timer); }, methods: { setSliderWidth() { this.children = this.$refs.slideGroup.children; let width = 0; let sliderWidth = this.$refs.slider.clientWidth; for(let i = 0; i < this.children.length; i ++){ this.children[i].style.width = window.screen.width + ''px''; width += sliderWidth; } if(this.loop){ width += 2*sliderWidth; } this.$refs.slideGroup.style.width = width + ''px'';// 最长的盒子 }, init(){ let vm = this; // 实例化scroll this.scroll = new BScroll(this.$refs.slider, { scrollX: true, scrollY: false, momentum: false, //关闭或者打开惯性运动的执行 snap: { loop: this.loop, // 循环 threshold: 0.3, speed: 400 // 轮播间隔 } }) this.scroll.on(''scrollEnd'', () => { let pageIndex = this.scroll.getCurrentPage().pageX; this.currentPageIndex = pageIndex; if(vm.autoPlay) { vm.play(); } }) this.scroll.on(''beforeScrollStart'', () => { if(vm.autoPlay){ clearTimeout(vm.timer); } }) }, _initDots() { this.dots = new Array(this.children.length) }, play() { let vm = this; this.timer = setTimeout(() => { vm.scroll.next(); },vm.interval) } } } </script> <style > .slide{ width: 100%; overflow: hidden; height: 150px; position: relative; } .slide-group{ height: 150px; } .slider-item{ float: left; height: 150px; } .dots{ position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; } .dot, .dotActive{ background: yellow; display: inline-block; margin: 0 4px; height: 20px; width: 20px; border-radius: 50%; } .dotActive{ background: red; } </style>

  

Django实现简单分页功能的方法详解

Django实现简单分页功能的方法详解

本文实例讲述了Django实现简单分页功能的方法。分享给大家供大家参考,具体如下:

使用django的第三方模块django-pure-pagination

安装模块:

pip install django-pure-pagination

将'pure_pagination'添加到settings.py文件中

INSTALLED_APPS = (
  ...
  'pure_pagination',)

在view.py文件中

from django.shortcuts import render
rom .models import mymodel
from pure_pagination import Paginator,EmptyPage,PageNotAnInteger
def NewsList(request):
  all_news = mymodel.objects.all().order_by('-add_time')
  # 分页功能
  try:
    page = request.GET.get('page',1)
  except PageNotAnInteger:
    page = 1
  p = Paginator(all_news,3,request=request)
  news = p.page(page)
  return render(request,'rdxw.html',{'all_news': news})

在template.py文件中调用view传递的参数'all_news'需要加上'.object_list'

{% extends 'base.html' %}
{% block content %}
<ul>
{% for new in all_news.object_list %}
  <li>{{new.content}}</li>
{% endblock %}
</ul>

实现翻页的部分:

<div>
  <ulhttps://www.jb51.cc/tag/Pagelist/" target="_blank">Pagelist">
    {% if all_news.has_prevIoUs %}
      <li><a href="?{{ all_news.prevIoUs_page_number.querystring }}" rel="external nofollow" >上一页</a></li>
    {% endif %}
    {% for page in all_news.pages %}
      {% if page %}
        {% ifequal page all_news.number %}
          <li><a href="?{{ page.querystring }}" rel="external nofollow" rel="external nofollow" >{{ page }}</a></li>
        {% else %}
          <li><a href="?{{ page.querystring }}" rel="external nofollow" rel="external nofollow">{{ page }}</a></li>
        {% endifequal %}
      {% else %}
        <li><a href="">...</a></li>
      {% endif %}
    {% endfor %}
    {% if all_news.has_next %}
      <li><a href="?{{ all_news.next_page_number.querystring }}" rel="external nofollow" >下一页</a></li>
    {% endif %}
  </ul>
</div>

样式较文档提供的简化了很多,方便使用。

.pageturn .Pagelist {
  display: table-cell;
  vertical-align: middle;
  overflow: hidden;
}
.pageturn li {
  width: 30px;
  height: 30px;
  line-height: 30px;
  margin-left: 10px;
  float: left;
  text-align: center;
}
.pageturn li:first-child {
  margin-left: 0;
}
.pageturn li:hover a,.pageturn .active a {
  background: #717171;
  color: #fff;
  border-color: #eaeaea;
}
.pageturn a {
  border: 1px solid #eaeaea;
  display: block;
  height: 28px;
  color: #6c6c6c;
}
.pageturn .long {
  width: 100px;
}
.pageturn .none a {
  border: 0;
}
.pageright {
  float: right;
  width: auto;
  display: inline;
  clear: none;
  margin-top: 10px;
}

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数据结构与算法教程》、《Python加密解密算法与技巧总结》、《Python编码操作技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》

希望本文所述对大家Python程序设计有所帮助。

关于iscroll.js实现简单分页js实现分页功能的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Android Gridview OnScrollListener ScrollUp和ScrollDown事件、asp.net实现简单分页实例、better-scroll 实现简单的轮播 无缝滚动~、Django实现简单分页功能的方法详解的相关知识,请在本站寻找。

本文标签:

上一篇又是克死在js上我就不信我学不好你。。。麻痹、

下一篇七夕情人节表白-纯JS实现3D心形+图片旋转(js绘制心形图案)