Commit 9fe1bc0a authored by wangqinghua's avatar wangqinghua

文章分类滚动

parent ffbe6935
...@@ -55,10 +55,10 @@ ...@@ -55,10 +55,10 @@
<div #fixedTab> <div #fixedTab>
<div class="fixed-toolbar parent-toolbar"> <div class="fixed-toolbar parent-toolbar">
<div class="tabs-fixed "> <div class="tabs-fixed ">
<div (scroll)="dragTo($event)" class="scroll-tab"> <div #scrollTab class="scroll-tab">
<ion-icon *ngIf="!toRight" class="icon-left" name="arrow-back"></ion-icon> <ion-icon *ngIf="!toRight" class="icon-left" name="arrow-back"></ion-icon>
<ion-icon *ngIf="toRight" class="icon-right" name="arrow-forward"></ion-icon> <ion-icon *ngIf="toRight" class="icon-right" name="arrow-forward"></ion-icon>
<div (scroll)="dragTo($event)" class="news-content parent"> <div #newContentParent (scroll)="dragTo($event)" class="news-content parent">
<div #tabsParent class="tabs-parent parent"> <div #tabsParent class="tabs-parent parent">
<div #tabsChildren *ngFor="let item of tabsList;" (click)="changeParent(item)" <div #tabsChildren *ngFor="let item of tabsList;" (click)="changeParent(item)"
class="tabs-children"> class="tabs-children">
......
...@@ -196,6 +196,10 @@ page-discover { ...@@ -196,6 +196,10 @@ page-discover {
.tabs-parent { .tabs-parent {
margin-bottom: 0px; margin-bottom: 0px;
background-color: #ffffff; background-color: #ffffff;
transition: all 500ms;
.tabs-children{
width: 90px;
}
} }
.parent.tabs-parent { .parent.tabs-parent {
......
...@@ -9,6 +9,7 @@ import {NoticePage} from "../notice/notice"; ...@@ -9,6 +9,7 @@ import {NoticePage} from "../notice/notice";
import {AppGlobal} from "../../../service/http.service"; import {AppGlobal} from "../../../service/http.service";
import {CommonService} from "../../../provide/common.service"; import {CommonService} from "../../../provide/common.service";
import {SwiperComponent} from "../../../components/swiper/swiper"; import {SwiperComponent} from "../../../components/swiper/swiper";
import {interval} from "rxjs/observable/interval";
declare let Swiper: any; declare let Swiper: any;
...@@ -26,6 +27,7 @@ export class DiscoverPage { ...@@ -26,6 +27,7 @@ export class DiscoverPage {
@ViewChild('tabsChildren') tabsChildren: ElementRef; @ViewChild('tabsChildren') tabsChildren: ElementRef;
@ViewChild('tabSpan') tabSpan: ElementRef; @ViewChild('tabSpan') tabSpan: ElementRef;
@ViewChild('newsContent') newsContent: ElementRef; @ViewChild('newsContent') newsContent: ElementRef;
@ViewChild('newContentParent') newContentParent: ElementRef;
@ViewChild('scrollTab') scrollTab: ElementRef; @ViewChild('scrollTab') scrollTab: ElementRef;
@ViewChild(Content) content: Content; @ViewChild(Content) content: Content;
...@@ -226,6 +228,9 @@ export class DiscoverPage { ...@@ -226,6 +228,9 @@ export class DiscoverPage {
} }
]; ];
itemWidth;
spanWidth;
constructor(public navCtrl: NavController, public navParams: NavParams, constructor(public navCtrl: NavController, public navParams: NavParams,
public commonSer: CommonService, public renderer: Renderer2, public commonSer: CommonService, public renderer: Renderer2,
public zone: NgZone, public zone: NgZone,
...@@ -239,6 +244,8 @@ export class DiscoverPage { ...@@ -239,6 +244,8 @@ export class DiscoverPage {
} }
ionViewDidLoad() { ionViewDidLoad() {
this.itemWidth = window.screen.width / 4;
this.spanWidth = this.tabSpan.nativeElement.offsetWidth; //文字宽度
this.initSwiper(); this.initSwiper();
this.getBanner(); this.getBanner();
this.slideList.length = 7; this.slideList.length = 7;
...@@ -263,6 +270,7 @@ export class DiscoverPage { ...@@ -263,6 +270,7 @@ export class DiscoverPage {
} }
} }
//文章分类固定
scrollHeight() { scrollHeight() {
const height = this.topHeight.nativeElement.offsetHeight; const height = this.topHeight.nativeElement.offsetHeight;
this.content.ionScroll.subscribe(($event) => { this.content.ionScroll.subscribe(($event) => {
...@@ -290,6 +298,18 @@ export class DiscoverPage { ...@@ -290,6 +298,18 @@ export class DiscoverPage {
slideChangeTransitionEnd: function () { slideChangeTransitionEnd: function () {
that.swiper.update(); that.swiper.update();
that.changeParent(that.tabsList[this.activeIndex]); that.changeParent(that.tabsList[this.activeIndex]);
const distancs = this.activeIndex * that.itemWidth/2; //滑动的长度
let scrollInter = window.setInterval(() => {
if (distancs == that.newContentParent.nativeElement.scrollLeft) {
window.clearInterval(scrollInter);
} else if (distancs > that.newContentParent.nativeElement.scrollLeft) {
that.newContentParent.nativeElement.scrollLeft++;
} else if (distancs < that.newContentParent.nativeElement.scrollLeft) {
that.newContentParent.nativeElement.scrollLeft--;
} else {
window.clearInterval(scrollInter);
}
}, 10)
} }
} }
}); });
...@@ -329,6 +349,7 @@ export class DiscoverPage { ...@@ -329,6 +349,7 @@ export class DiscoverPage {
}); });
} }
//前往主题教育 //前往主题教育
goEdu() { goEdu() {
this.swiper.slideTo(1, 500); //前往主题教育 this.swiper.slideTo(1, 500); //前往主题教育
...@@ -379,11 +400,9 @@ export class DiscoverPage { ...@@ -379,11 +400,9 @@ export class DiscoverPage {
this.resourceType = item.name == "知识拓展" ? 3 : 1; this.resourceType = item.name == "知识拓展" ? 3 : 1;
this.isRecent = this.obj.parentName == "最新发布" ? 1 : 0; this.isRecent = this.obj.parentName == "最新发布" ? 1 : 0;
if (this.childrenList.length > 0) this.indexChildren = this.childrenList[0].indexChildren; if (this.childrenList.length > 0) this.indexChildren = this.childrenList[0].indexChildren;
let itemWidth = window.screen.width / 4;
let spanWidth = this.tabSpan.nativeElement.offsetWidth; //文字宽度
this.tips.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px'; this.tips.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
// 自身div的一半 - 滑块的一半 // 自身div的一半 - 滑块的一半
this.tips.nativeElement.style.left = itemWidth * (this.indexParent) + (itemWidth - spanWidth) / 2 + 'px'; this.tips.nativeElement.style.left = this.itemWidth * (this.indexParent) + (this.itemWidth - this.spanWidth) / 2 + 'px';
const data = { const data = {
pageSize: 1, pageSize: 1,
pageCount: this.pageCount, pageCount: this.pageCount,
...@@ -462,7 +481,7 @@ export class DiscoverPage { ...@@ -462,7 +481,7 @@ export class DiscoverPage {
} }
getMore(res) { getMore(res) {
const totalNum:number = res.data.total; const totalNum: number = res.data.total;
if (totalNum < this.pageCount) return false; if (totalNum < this.pageCount) return false;
this.pageNum++; this.pageNum++;
const data = { const data = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment