利用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,一经查实,立即删除!

相关文章

05 state与setState、单向数据流

声明周期与组件卸载 props配置&#xff1a;使用组件时传入数据state私有数据&#xff1a;组件内部使用的数据 state的使用注意事项 必须使用setState方法来更改state多个setState会合并调用props和state更新数据要谨慎&#xff08;有可能在异步程序中更新&#xff09;setState…

HDU 3342 Legal or Not(拓扑排序)

描述 ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just like a big family. Every day,many "holy cows" like HH, hh, AC, ZT, lcc, BF, Qinz and so on chat on-line to exchange their ideas. When someone…

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");…

vuex复习笔记

npm install vuex --save 进行安装 vuex import Vuex from vuex 新建一个vuex文件夹&#xff08;这个不是必须的&#xff09;&#xff0c;并在文件夹下新建store.js文件&#xff0c;文件中引入我们的vue和vuex。 转载于:https://www.cnblogs.com/jinsuo/p/8508699.html

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.…

css -- 两种方法实现流式布局

Bootstrap将屏幕分为4个等级: 1.超小屏幕 (宽度小于768 px), 显示宽度 100%; 2.小屏幕 (宽度在768px ~ 992px), 显示宽度 750px; 3.中等屏幕 (宽度在992px ~ 1200px), 显示宽度 970px; 4.大屏幕 (宽度大于1200px), 显示宽度 1170px. js实现: window.addEventListener("r…

python文件名匹配

待匹配文件&#xff1a;#FY3D_IPMNT_GBAL_L1_20180516_0003_030KM_MS.HDF 干扰文件&#xff1a;#FY3D_IPMNT_GBAL_L1_20180516_0003_030KM_MS_uuu.HDF 1.正则表达式import reif re.findall(FY3D_IPMNT_GBAL_L1_\d_\d_030KM_MS.HDF,fileEvery): fileList.append(os.path.join(in…

【XSY1594】棋盘控制 概率DP

题目描述 给你一个\(n\times m\)的棋盘&#xff0c;每次随机在棋盘上放一个国际象棋中的车&#xff0c;不能和以前放的重叠。每个车可以控制当前行和当前列。当所有行和所有列都被控制时结束游戏。问你结束时期望放了多少个车。 注意&#xff1a;结束的条件是所有行和所有列都被…

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

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

链表的翻转

public ListNode reverseListNode(ListNode node){ ListNode pre null; ListNode now node;//当前节点 while (now !null){ ListNode after now.next; now.next pre; pre now; now after; } …

面向对象命名空间、组合

一 类命名空间与对象、实例的命名空间 创建一个类就会创建一个类的名称空间&#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…

09 受控组件

含义 受控组件&#xff1a;由state来决定表单内部的数据&#xff0c;由表单的事件处理函数来更改state的方式 class App extends React.Component {// 1. state是表单的唯一数据源state {name: }handleChange (e) > {// 2. 控制表单操作并同步statethis.setState({name:…

剑指Offer--青蛙跳台阶引发的一系列问题

题目描述 一只青蛙一次可以跳上1级台阶&#xff0c;也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法&#xff08;先后次序不同算不同的结果&#xff09;。解法一&#xff08;效率最高&#xff09;数学归纳法&#xff1a;public class Solution {public int JumpFloo…

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…

day9-Python学习笔记(二十)数据库备份,修改父类的方法

数据库备份&#xff0c;修改父类的方法 import os,datetimeclass BakDb(object): def __init__(self,ip,username,passwd,port3306,path/tmp/db_bak): self.ip ip self.username username self.passwd passwd self.port port self.path path …

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…