利用ionic3进行上一行和左一行不动,中间移动的功能

首先在html中的写法是

<ion-header>

<ion-navbar>
<ion-title>历史数据</ion-title>
</ion-navbar>
</ion-header>

<ion-content >

<div style="display:flex;width:625px;">
<div class="head">地区</div>
<div style="overflow: hidden;white-space: nowrap;width:250px;height: 50px;" >
<ion-scroll #scroll1 scrollX="true" overflow-scroll="true" has-bouncing="false" (onScroll)="addScrollEventListener()" style="margin-top:0;height:50px">
<div style="display:flex;width:500px;height:50px" id="right">
<div class="head" >到件量</div>
<div class="head">出仓量</div>
<div class="head">滞留量</div>
<div class="head" style="border-right:0;">未派送量</div>
</div>
</ion-scroll>
</div>
</div>


<div style="display:flex;width:625px;height: 650px;white-space: nowrap;" >
<ion-scroll #scroll2   scrollY="true" overflow-scroll="true" has-bouncing="false" style="height:550px;width: 125px">
<div *ngFor="let d of data" class="head" >
{{d.zoneName}}
</div>
</ion-scroll>
<div style="overflow: hidden;white-space: nowrap;width:250px">
<ion-scroll direction="xy" #scroll3 scrollX="true" scrollY="true" overflow-scroll="false" has-bouncing="false" delegate-handle="rightContainerHandle" style="height:550px;">
<div style="width:500px;" >
<div *ngFor="let d of data" style="display:flex;" >
<div class="head" >
{{d.arriveTickets}}
</div>
<div class="head">
{{d.moniOutCnt}}
</div>
<div class="head">
{{d.moniStayCnt}}
</div>
<div class="head" style="border-right:0;">
{{d.moniUndeliveryCnt}}
</div>
</div>
</div>
</ion-scroll>
</div>
</div>
</ion-content>
标红颜色的首先是在ts中滚动时需要用到的变量,是个标识符。这个问题我纠结了两天才搞出来。一定记得滚动的监听事件不是on-scroll了

ts中的代码

 

 

import { Component, SystemJsNgModuleLoader,HostListener,NgZone ,ViewChild } from '@angular/core';
import { NavController, NavParams,IonicPageModule} from 'ionic-angular';
import{RestProvider} from '../../providers/rest/rest';
import {Http,Response, Jsonp} from '@angular/http';
import { IonicModule } from 'ionic-angular';
import { NgModule, ErrorHandler ,CUSTOM_ELEMENTS_SCHEMA, SchemaMetadata} from '@angular/core';
import { Directive, ElementRef, Output,Input, EventEmitter } from '@angular/core';
import { ScrollEventModule,ScrollEvent } from 'ngx-scroll-event';
import {Content,Scroll,Spinner} from 'ionic-angular'
import { asElementData } from '@angular/core/src/view';

/**
* Generated class for the AlarmPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/

@Component({
selector: 'page-rank',
templateUrl: 'rank.html',
})
@NgModule({

imports: [IonicModule,IonicPageModule,ScrollEventModule]
})
export class RankPage {
@Output() scrollChange = new EventEmitter<number>();

@ViewChild(Spinner) spinnerElement: Spinner;
@ViewChild(Content) content: Content;
@ViewChild('scroll3') scroll3: Scroll;
@ViewChild('scroll1') scroll1: Scroll;
@ViewChild('scroll2') scroll2: Scroll;
 
//括号中的值在html页面中标注的时候,名称不能其他属性相同。如该文件已经有一个pnavs的变量,则会报错。
addScrollEventListener() {
this.scroll2._scrollContent.nativeElement.onscroll = event => {
this.scroll3._scrollContent.nativeElement.scrollTop =this.scroll2._scrollContent.nativeElement.scrollTop;
// this.scroll1._scrollContent.nativeElement.scrollLeft =this.scroll2._scrollContent.nativeElement.scrollLeft;
}
this.scroll1._scrollContent.nativeElement.onscroll = event => {
//this.scroll3._scrollContent.nativeElement.scrollTop =this.scroll2._scrollContent.nativeElement.scrollTop;
this.scroll3._scrollContent.nativeElement.scrollLeft =this.scroll1._scrollContent.nativeElement.scrollLeft;
}
this.scroll3._scrollContent.nativeElement.onscroll = event => {
this.scroll2._scrollContent.nativeElement.scrollTop =this.scroll3._scrollContent.nativeElement.scrollTop;
this.scroll1._scrollContent.nativeElement.scrollLeft =this.scroll3._scrollContent.nativeElement.scrollLeft;
}

}
ionViewDidLoad() {
this.addScrollEventListener();
}
data=[
{'zoneName':'广州区','arriveTickets':'6987','moniOutCnt':'2221','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'深圳区','arriveTickets':'2356','moniOutCnt':'331','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'武汉区','arriveTickets':'6744','moniOutCnt':'2621','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'苏州区','arriveTickets':'6542','moniOutCnt':'2881','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'杭州区','arriveTickets':'2367','moniOutCnt':'5621','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'东莞区','arriveTickets':'1129','moniOutCnt':'1221','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'惠州区','arriveTickets':'7893','moniOutCnt':'4521','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'汕头区','arriveTickets':'2356','moniOutCnt':'7821','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'清远区','arriveTickets':'67554','moniOutCnt':'9921','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'长沙区','arriveTickets':'5534','moniOutCnt':'2221','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'岳阳区','arriveTickets':'6643','moniOutCnt':'2221','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'株洲区','arriveTickets':'6546','moniOutCnt':'2221','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'南充区','arriveTickets':'4353','moniOutCnt':'2221','moniStayCnt':'45','moniUndeliveryCnt':'44'},
{'zoneName':'鞍山区','arriveTickets':'4526','moniOutCnt':'2221','moniStayCnt':'45','moniUndeliveryCnt':'44'}
];
city=["杭州","郑州","上海","广州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州","杭州",];
stylefor=["含氮量","含磷量","含钾量","含氮量","含磷量","含钾量","含氮量","含磷量","含钾量","含氮量","含磷量","含钾量","含氮量","含磷量","含钾量","含氮量","含磷量","含钾量",];
d=[1,2,3,4,5,6,7,8,9];
list=[];
public items:any=[];
constructor(public navCtrl: NavController,public rest:RestProvider,public jsonp:Jsonp,public http:Http,public zone: NgZone,private el: ElementRef) {//首次打开要显示的数据
this.geturl();
}
geturl(){
//console.log(this.getData("http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=2&callback=JSONP_CALLBACK"));
//var list=this.getData("http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=2&callback=JSONP_CALLBACK");
this.jsonp.get("http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=2&callback=JSONP_CALLBACK").subscribe(function(data){
console.log(data["_body"]);
});
this.http.get("http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=2").subscribe(function(data){
console.log(JSON.parse(data["_body"]));
});
}
public getData(url:string):any{
var rs=this.list;
this.jsonp.get(url).subscribe(function(data){
console.log(data["_body"]["result"]);
var resData:any[]=data["_body"]["result"];
for(var i=0;i<resData.length;i++){
rs.push(resData[i])
}
},function(err){
console.log(err)
})
return this.list;
}


}
ts中标红的代码是前面html标红的相呼应,然后addScrollEventListener进行滚动的监听 注意:  ionViewDidLoad()这个是ionic3本身的方法,只要触动页面,就能调用这个方法,无论点击还是拉动。
然后就是
this.scroll2._scrollContent.nativeElement.onscroll = event => {
this.scroll3._scrollContent.nativeElement.scrollTop =this.scroll2._scrollContent.nativeElement.scrollTop;
// this.scroll1._scrollContent.nativeElement.scrollLeft =this.scroll2._scrollContent.nativeElement.scrollLeft;
}就是监听事件,只要滑动就能触发的事件

css代码

 

 

 

*{

 

margin:0px;

 

padding:0px;

 

}

 

.focus{

 

height: 150px;

 

width: 100%;

 

ion-slide{

 

height: 150px;

 

width: 100%;

 

img{

 

height: 150px;

 

width: 100%;

 

}

 

}

 

}

 

.slide_product{

 

//滚动

 

ion-scroll{

 

 

width:100%;

 

height:800px;

 

 

}

 

ul{

 

list-style: none;

 

padding: 0px 5px;

 

li{

 

width: 80px;

 

height: 120px;

 

float: left;

 

margin-right: 10px;

 

p{

 

padding:4px;

 

margin:0px;

 

}

 

 

}

 

}

 

 

}

 

.home_title{

 

 

 

height: 50px;

 

width: 100%;

 

background-image: url("../../assets/imgs/pict1.jpg");

 

 

}

 

.home_title{

 

height: 50px;

 

}

 

.cate_content{

 

width:100%;

 

height: 100%; /*首先看高度100% 是否管用 如果没有作用我们要给元素设置绝对定位*/

 

display: flex;

 

.cate_left{

 

 

width: 100px;

 

height: 100%;

 

overflow-y: auto;

 

 

}

 

.cate_right{

 

height: 100%;

 

flex:1;

 

margin-left:5px;

 

overflow-y: auto;

 

 

}

 

}

 

table.gridtable {

 

    font-family: verdana,arial,sans-serif;

 

font-size:11px;

 

    color:#333333;

 

    border-width: 1px;

 

    border-color: #666666;

 

    border-collapse: collapse;

 

}

 

table.gridtable th {

 

    border-width: 1px;

 

padding: 8px;

 

width:2%;

 

    border-style: solid;

 

    border-color: #666666;

 

    background-color: #dedede;

 

}

 

table.gridtable td {

 

    border-width: 1px;

 

padding: 8px;

 

width:2%;

 

    border-style: solid;

 

    border-color: #666666;

 

background-color: #ffffff;

 

color: #f53d3d;

 

}

 

.head{

 

border-bottom:solid 1px #D1D3D6;

 

border-right:solid 1px #D1D3D6;

 

height:50px;

 

display:flex;

 

align-items:center;

 

width:125px;

 

font-size:14px;

 

color:#262626;

 

justify-content:center;

 

}

代码效果图如下

 

2018-08-17

 

 

转载于:https://www.cnblogs.com/shangyunlin/p/9494934.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/250910.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

jquery --- 阻止表单默认的提交行为,标准化表单的数据

表单如下: // .html <form id"topics_new_form" method"post" action"/topics/new"><div class"form-group"><label for"exampleInputEmail1">选择模块</label><selecet class"form-contr…

javascript --- spa初体验

首先使用express创建一个简单的服务器 创建文件夹 be-project # (确保安装了node,并配置好了环境) 在be-project目录下(命令行执行) npm init -y npm install --save express body-parse npm install --global nodemon// app.js const express require("express");…

python学习HTML之CSS(2)

1、边框的属性设置 PS&#xff1a;边框的高度和宽度可以采用百分比&#xff0c;但是高度方向的百分比基本无用&#xff0c;因为基数没定&#xff0c;参考没意义&#xff01;&#xff01; 2、内边距和外边距 3、在右下角添加一个“回顶部”的标签。 <div></div>中的…

06 事件处理函数绑定与事件对象

事件处理函数绑定 DOM事件处理 addEventListener or onclick function(){} 纯小写React元素也采用了类似DOM0标准中的事件属性定义的方法 小驼峰 JSX <button onClick{ this.doSth }></button>直接创建React元素 React.createElement(button,{onClick: { this.…

07、08 条件渲染、列表渲染

条件渲染 React没有像v-if、v-show这样的指令&#xff0c;需要使用JSX表达式组合而成 // 与运算 三目 // 判断表达式一定是false/null/undefined时才不会被渲染&#xff0c;0、空字符串、NaN会显示 // 如果render函数返回null&#xff0c;不会进行任何渲染 ......state {showL…

面向对象命名空间、组合

一 类命名空间与对象、实例的命名空间 创建一个类就会创建一个类的名称空间&#xff0c;用来存储类中定义的所有名字&#xff0c;这些名字称为类的属性 而类有两种属性&#xff1a;静态属性和动态属性 静态属性就是直接在类中定义的变量动态属性就是定义在类中的方法class Pers…

css --- 使用媒体查询当屏幕宽度小于某个值时,隐藏掉某个类

Bootstrap提供了一个封装好的类: .hidden-xs: 当屏幕宽度<768px时隐藏 .hidden-sm: 当屏幕768px < 宽度<992px时隐藏 .hidden-md: 当屏幕992px< 宽度<1200px时隐藏 .hidden-lg: 当屏幕宽度>1200px时隐藏 下面使用css3的 媒体查询来实现: media screen and…

css --- 伸缩布局,让图片居中

很明显,想要星星位于文字的正下方. // html <section id"lz_about" class"hidden-xs hidden-sm"><div class title text-center"><h1><strong>关于我</strong></h1><img src"./imgs/star.jpg" cla…

10 非受控组件以及受控与非受控的选择方案

含义 非受控组件&#xff1a;表单数据不受控与state的&#xff08;未绑定value&#xff09;&#xff0c;使用React ref从DOM节点中获取表单数据的组件提示refs弃用 class MyForm extends React.Component {constructor(props) {super(props)}submit (e) > {e.preventDef…

wampserver3.0.6 外网 不能访问

# 开始 今天在服务器上安装了wampserver3.0.6 然后在我的电脑浏览器上面打开服务器ip提示 Forbidden 下面一行小字提示没有权限访问"/"目录 # 解决 打开 httpd-vhost.conf 文件 修改成如下 # Virtual Hosts #<VirtualHost *:80>ServerName localhostServerAlia…

javascript --- 在linux上部署项目

最近对照视频,用bootstrap jquery 写了一个纯前端页面.想把它放在服务器上,供远程使用. 准备服务器和域名 我服务器和域名是在腾讯云上租的,网址: https://cloud.tencent.com/ 注: 域名很便宜,挑个好的哈哈哈… 服务器(阿里云有个学生价…但是我那个学生价的账号找不到了…)…

11 父子组件数据关系与状态提升

含义 状态提升&#xff1a;两个组件&#xff08;无父子关系&#xff09;共享一个数据并且同步数据变化类组件调用&#xff08;实例化&#xff09;的时候&#xff0c;组件内部的状态是唯一且独立的组件嵌套与调用&#xff0c;和是类组件&#xff08;render&#xff09;还是函数…

工具分享 --- 分享一个在线制作ico的网站

还不错… 生成后一般放在imgs的下面. link:favicon tab 导入链接http://www.faviconico.org/

laravel迁移文件

laravel迁移文件的命令 Laravel鼓励敏捷、迭代的开发方式&#xff0c;我们没指望在第一次就获得所有正确的。我们对于自己编写代码,可以通过迁移文件,不断的重复去测试.对于工作&#xff0c;我们开发一个完整的项目,是需要我们每个人相互配合,就好比用svn,git版本控制工具来存储…

12 组合与继承、CSS Module

组合与继承 若Container内部有内容&#xff0c;React会在props内部增加children属性若Container内部有非元素内容&#xff0c;children&#xff1a;非元素内容若Container内部有单个元素内容&#xff0c;children&#xff1a;React元素对象若Container内部有多个元素内容&…

工具分享 --- tinyPNG,大图片压缩工具

今天自己的写的项目跑在了远程服务器上… 图片加载的速度让人难以接受, 于是各种百度找到了一个在线找到了个图片压缩的网站 TinyPNG 可以看一下压缩的效果…真心不错啊… 网站如下: https://tinypng.com 额…有些大于5M的需要钱,才能压缩… 用系统画图工具…貌似也能压缩… …

14 代码分割之lazy:Suspense与路由懒加载

lazy内置方法 Suspense内置组件 lazy是React提供的懒&#xff08;动态&#xff09;加载组件的方法&#xff0c;React.lazy() 能减少打包体积、延迟加载首屏不需要渲染的组件 依赖内置组件Suspense&#xff1a;给lazy加上loading指示器组件的一个容器组件 Suspense目前只和la…

css --- 兄弟选择器

语法: /* 查找后边的一个兄弟元素 */ 兄弟元素 兄弟元素/* 查找后边的所有兄弟元素 */ 兄弟元素 ~ 兄弟元素<head><style>#maindiv {color: red;}#main~div {background-color: #e0e0e0;}</style> </head> <body><div id"main"&g…

15 错误边界与使用技巧

错误边界 React16增加防止某个组件的UI渲染错误导致整个应用崩溃子组件发生JS错误&#xff0c;有备用的渲染UI错误边界是组件&#xff0c;只能用class组件来写 错误边界组件捕获错误的时机 渲染时生命周期函数中组件树的构造函数中 getDerivedStateFromError 生命周期函数…

es6 --- Promise.all等待多个异步任务执行

项目中遇到一个问题,要用多个http请求,获取数据,然后将获取的数据统一处理… 第一反应想到用promise.all来做… 下面进入主体 // 首先使用promise封装http请求. function getListByDetecttype (params) {return new Promise((resolve, reject) > {let param params ? par…