利用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.pswp.cn/news/250910.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/250910.shtml
英文地址,請注明出處:http://en.pswp.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…