首先安装 swiper npm install --save swiper 或者 bower install --save swiper

<link rel="stylesheet" href="../bower_components/swiper/dist/css/swiper.min.css" />
<script src="../bower_components/swiper/dist/js/swiper.jquery.min.js"></script>

指令文件代码

(function() {
'use strict'; angular
.module('campus.core')
.directive('swiperSlide',swiperSlide)
.directive('goToTop',goToTop); swiperSlide.$inject = ['$timeout'];
function swiperSlide($timeout) {
return {
restrict: "EA",
link: function(scope, element, attrs) {
$timeout(function(){
var swiper2 = new Swiper('.swiper-container2', {
slidesPerView: 'auto',
freeMode: true
});
},);
}
};
} goToTop.$inject = ['$ionicScrollDelegate','$timeout']; //ionic中返回顶部的方法 $ionicScrollDelegate
function goToTop($ionicScrollDelegate,$timeout) {
return {
restrict: "EA",
scope: {
reload: "&"
},
template: '<span id="goToTop" class="goToTop"></span>',
link: function(scope, element, attrs) {
element.bind('click',function(){
$timeout(function(){
var scroll = parseInt(document.getElementById('goToTop').offsetTop) - parseInt($ionicScrollDelegate.getScrollPosition().top);
var scroll = scroll-document.getElementById('goToTop').offsetTop;
$ionicScrollDelegate.resize();
$ionicScrollDelegate.scrollBy(,scroll,true); //大于两页时显示分页
},); }) }
};
} })();

回到顶部的逻辑

回到顶部对应的对应html中的内容

<go-to-top></go-to-top>

回到顶部按钮css文件

.goToTop{width:4.17rem;height: 4.17rem;position: fixed;bottom:2.6rem;right: 1.25rem;z-index:;background: url(../assets/images/goToTop.png) no-repeat;background-size: contain;display: none;}
.goToTop.none{display: none;}

左右滑动对应的html代码

<div class="index-tab zw-tab s15">
<ul class="swiper-wrapper">
<li class="swiper-slide" ng-repeat="items in vm.data" ng-click="vm.switchType(items.type,$index)">
<span ng-class="{'active':$index==vm.typeOn}">{{items.typeName}}</span>
</li>
</ul>
</div>
             vm= this;
vm.typeOn = 0; //默认第一个高亮显示
vm.switchType =function(type,index){
vm.typeOn = index;
vm.type = type;
initList(type,0); //类型对应的数据请求 }
$ionicScrollDelegate

angularjs 水平滚动选中按钮高亮显示 swiper和回到顶部指令的实现ionic的更多相关文章

  1. 页面滚动事件和利用JS实现回到顶部效果

    页面滚动 事件:window.onscroll, 获得页面滚动位置:document.body.scrollTop: HTML代码: 这里注意此处逻辑,大于500就显示,否则就隐藏,还有注意如果变量名 ...

  2. 【demo练习三】:图片水平滚动、点击按钮变更图片动画

    要求:四张图片水平滚动,每隔5秒进行一次循环,点击按钮随机变更图片. XAML前台代码: <Window x:Class="图片滚动.MainWindow" xmlns=&q ...

  3. IOS UIScrollView + UIButton 实现segemet页面和顶部标签页水平滚动效果

    很长一段时间没有写博客了,最近在学习iOS开发,看了不少的代码,自己用UIScrollView和UIButton实现了水平滚动的效果,有点类似于今日头条的主界面框架,效果如下: 代码如下: MyScr ...

  4. jquery 文字滚动大全 scroll 支持文字或图片 单行滚动 多行滚动 带按钮控制滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. Android中如何实现多行、水平滚动的分页的Gridview?

    功能要求: (1)比如每页显示2X2,总共2XN,每个item显示图片+文字(点击有链接). 如果单行水平滚动,可以用Horizontalscrollview实现. 如果是多行水平滚动,则结合Grid ...

  6. [iOS] UICollectionView实现图片水平滚动

    最新更新: 简单封装了一下代码,参考新文章:UICollectionView实现图片水平滚动 先简单看一下效果: 新博客:http://wossoneri.github.io 准备数据 首先先加入一些 ...

  7. ASP.NET中使用JavaScript实现图片自动水平滚动效果

    参照网上的资料,在ASP.NET中使用JavaScript实现图片自动水平滚动效果. 1.页面前台代码: <%@ Page Language="C#" AutoEventWi ...

  8. [转]HorizontalScrollView介绍--支持水平滚动的android布局容器

    类概述 用 于布局的容器,可以放置让用户使用滚动条查看的视图层次结构,允许视图结构比手机的屏幕大.HorizontalScrollView是一种 FrameLayout(框架布局),其子项被滚动查看时 ...

  9. HorizontalScrollView水平滚动控件

    HorizontalScrollView水平滚动控件 一.简介 用法ScrollView大致相同 二.方法 1)HorizontalScrollView水平滚动控件使用方法 1.在layout布局文件 ...

随机推荐

  1. linux下如何查看mysql、apache是否安装,并卸载

    --linux下如何查看mysql.apache是否安装,并卸载? http://blog.163.com/dengxiuhua126@126/blog/static/1186077720137311 ...

  2. lua 运算符

    lua 运算符 算术运算符 操作符 描述 + 加 - 减 * 乘 / 除 % 求模 ^ 求幂 示例程序 local a, b = 1, 2 print(a + b) print(a - b) prin ...

  3. Mac Hadoop2.7.2的安装与配置

    这里介绍Hadoop 2.7.2在mac下的安装与配置. 安装及配置Hadoop 首先安装一下Hadoop $ brew install Hadoop 配置ssh免密码登录 用dsa密钥认证来生成一对 ...

  4. Spring数据库访问

    一般采用第三方具有连接缓冲池的数据源实现类:spring支持最常见的两个具有连接缓冲池的数据源为:DBCP和C3P0; DBCP(Database connection pool) 是Apache的一 ...

  5. 容易产生错误的where条件

    错误的方式:$where = [];if ($type == 'wait') { $where['status'] = 0;}if ($type == 'done') { $where['status ...

  6. bootstrap快速入门笔记(二)-栅格系统,响应式类

    一,栅格系统大致有以下: 1,行row必须包含在 .container (固定宽度)或 .container-fluid (100% 宽度)中,一行有12列 2.“列(column)”在水平方向创建一 ...

  7. openresty源码剖析——lua代码的加载

    ##Openresty是什么 OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,通过把lua嵌入到Nginx中,使得我们可以用轻巧的lua语言进行nginx的相关开发,处理 ...

  8. 深入解析MySQL视图view

    阅读目录---深入解析MySQL视图view 创建视图 查看视图 视图的更改 create or replace view alter DML drop 使用with check option约束 嵌 ...

  9. C++学习 cout的格式化输出

    cout的格式化输出 1.常用: ①double 输出到小数点后n位:(保留精度 n位) #include <iostream> #include <iomanip> usin ...

  10. ④JavaScript格式化时间戳

    这部分代码是按照网上的教程写的,忘记在哪里看到了