angularjs1 自定义轮播图(汉字导航)
本来想用swiper插件的,可是需求居然说要汉字当导航栏这就没办法了,只能自己写。
directive
// 自定义指令: Home页面的轮播图
app.directive('swiperImg', ["$interval", function ($interval) {
return {
restrict: 'E',
replace: true,
scope: { imgList: "=", tabList: "=", autoplay : "="},
template: '<div class="swiper-container"><ul class="swiper-wrapper" >' +
'<li class="swiper-wrapper-items" ng-repeat="item in imgList" ng-class="{ imgActive : isSelImg(item) }"><img ng-src="{{item.src}}" /></li>' +
'</ul><ul class="swiper-pagination"><li class="pagination-item" ng-repeat="item in tabList" ng-mouseover="hoverTab($index)" ng-mouseleave="leaveTab($index)" ng-class="{ imgActive : isSelImg(item) }">{{ item.name }}</li></ul></div>',
link: function ($scope, elem, attr) {
var i = 0;
var imgInterval;
$scope.hoverTab = function (index) {
$scope.hoverImg = index;
$scope.isSelImg(index);
i = index;
$interval.cancel(imgInterval);
}
$scope.leaveTab = function (index) {
imgInterval = $interval(function () {
if (i == $scope.imgList.length) {
i = 0;
}
$scope.hoverImg = i;
$scope.isSelImg(i);
i++;
}, $scope.autoplay);
}
imgInterval = $interval(function () {
if (i > 3) {
i = 0;
}
$scope.hoverImg = i;
$scope.isSelImg(i);
i++;
}, $scope.autoplay);
$scope.isSelImg = function (item) {
return $scope.hoverImg == item.id;
}
$scope.hoverImg = i;
$scope.isSelImg(i);
}
};
}]);
CSS
.swiper-container {
margin: 0 auto;
position: relative;
overflow: hidden;
z-index:;
width: 100%;
height: 100%;
}
.swiper-wrapper{
height: 200px;
width: 100%;
}
.swiper-wrapper-items {
height: 100%;
position: absolute;
width: 100%;
opacity:;
transition: opacity .8s;
-moz-transition: opacity .8s;
-webkit-transition: opacity .8s;
-o-transition: opacity .8s;
}
.imgActive.swiper-wrapper-items {
opacity:;
}
.swiper-container img {
width: 100%;
height: 100%;
}
.swiper-pagination {
display: box;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
bottom: 0 !important;
position: absolute;
left:;
right:;
text-align: center;
z-index:;
}
.pagination-item:first-child {
background-color: rgba(60,141,188,0.5);
}
.pagination-item:nth-child(2) {
background-color: rgba(202,64,64,0.5);
}
.pagination-item:nth-child(3) {
background-color: rgba(255,134,4,0.5);
}
.pagination-item:last-child {
background-color: rgba(34,172,56,0.5);
}
.imgActive.pagination-item:first-child {
background-color: rgba(60,141,188,1);
}
.imgActive.pagination-item:nth-child(2) {
background-color: rgba(202,64,64,1);
}
.imgActive.pagination-item:nth-child(3) {
background-color: rgba(255,134,4,1);
}
.imgActive.pagination-item:last-child {
background-color: rgba(34,172,56,1);
}
.pagination-item {
-webkit-box-flex:;
-moz-box-flex:;
-webkit-flex:;
-ms-flex:;
flex:;
-webkit-user-select: none; /* Chrome all / Safari all /opera15+*/
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none;
cursor: pointer;
color: #fff;
padding: 10px;
transition: all .8s;
-moz-transition: all .8s;
-webkit-transition: all .8s;
-o-transition: all .8s;
}
引用
<swiper-img img-list="imgList" tab-list="tabList" autoplay="autoplay"></swiper-img>
控制器
$scope.tabList = [{ id: 0, name: "开拓创新" }, { id: 1, name: "高效务实" }, { id: 2, name: "利益客户" }, { id: 3, name: "成就员工" }];
$scope.imgList = [{ id: 0, src: "@Url.Content("~/Content/images/u3.jpg")" }, { id: 1, src: "@Url.Content("~/Content/images/bg1.png")" },
{ id: 2, src: "@Url.Content("~/Content/images/bg2.png")" }, { id: 3, src: "@Url.Content("~/Content/images/bg3.png")" }];
$scope.autoplay = 5000;
tabList 是汉字导航栏
imgList 是图片链接数组
autoplay 是切换时间
效果图


好的,完成了。
angularjs1 自定义轮播图(汉字导航)的更多相关文章
- 【自定义轮播图】微信小程序自定义轮播图无缝滚动
先试试效果,可以通过设置参数调整样式 微信小程序中的轮播图可以直接使用swiper组件,如下: <swiper indicator-dots="{{indicatorDots}}&qu ...
- 带轮播图、导航栏、商品的简单html,以及轮播图下边数字随轮播图的改变而改变
---恢复内容开始--- 在做这个的时候,最不会的是中间轮播图下边的数字是如何实现转变的,后来加入了jQuery就能实现了. css部分: <style type="text/css& ...
- vue自定义轮播图组件 swiper
1.banner 组件 components/Banner.vue <!-- 轮播图 组件 --> <template> <div class="swiper- ...
- taro 自定义 轮播图组件
1.代码 components/MySwiper/index.js /** * 轮播图组件 */ import Taro, { Component } from '@tarojs/taro'; imp ...
- BootStrap自定义轮播图播放速度
$('.carousel').carousel({ interval: 3000 });
- 前台主页搭建、后台主页轮播图接口设计、跨域问题详解、前后端互通、后端自定义配置、git软件的初步介绍
今日内容概要 前台主页 后台主页轮播图接口 跨域问题详解 前后端打通 后端自定义配置 git介绍和安装 内容详细 1.前台主页 Homeviwe.vue <template> <di ...
- swift-自定义无限轮播图
一 前言 1.之前一直在用OC编程,最近才开始接触使用swift就发现使用OC越来越不习惯,感觉已经爱上了swift. 2.这个自定义轮播图只是对之前OC版本进行了翻译,欢迎指正. 3.我决定一步步 ...
- Android开发之ViewPager实现轮播图(轮播广告)效果的自定义View
最近开发中需要做一个类似京东首页那样的广告轮播效果,于是采用ViewPager自己自定义了一个轮播图效果的View. 主要原理就是利用定时任务器定时切换ViewPager的页面. 效果图如下: 主页面 ...
- android ViewPager实现的轮播图广告自定义视图,网络获取图片和数据
public class SlideShowAdView extends FrameLayout { //轮播图图片数量 private static int IMAGE_COUNT = 3; ...
随机推荐
- Apache配置HTTPS的过程小记
一.HTTPS的summery,综述,它的基本原理,扫肓. http://www.codeceo.com/article/https-knowledge.html 读过后,就明白https怎么加密的, ...
- mysql 建立表之间关系 练习 2
创建数据库db6 create database db6 charset=utf8; user db6; # 创建班级表 mysql) not null unique); Query OK, rows ...
- 访问url
你可以通过 args 属性来访问 URL 中提交的参数 ( ?key=value ): searchword = request.args.get('q', '') from flask import ...
- Oracle_trunc截取函数
转:http://blog.sina.com.cn/s/blog_6b58d2fa0100r6ub.html TRUNC函数用于对值进行截断. 用法有两种:TRUNC(NUMBER)表示截断数字,TR ...
- webservice -- cxf客户端调用axis2服务端
背景: 有个项目, 需要由第三方提供用户信息, 实现用户同步操作, 对方给提供webservice接口(axis2实现)并也使用axis2作主客户端调用我方提供的webservice接口 起初, 由于 ...
- 分支语句(switch case)
/switch case 的应用 Console.WriteLine("1.汉堡包"); Console.WriteLine("2.薯条"); Console. ...
- Linux网络接口配置文件ifcfg-eth0解析
本文转自:http://blog.csdn.net/jmyue/article/details/17288467 在Windows上配置网络比较容易,有图形化界面可操作.在Linux中往往是通过命令修 ...
- ios 中实现storyboard 与xib 之间的切换
1,跳转到xib 假设有一个按钮,这个按钮就是实现跳转的,那么在这个按钮的点击事件中,代码可以这样写. AViewController *a1= [[AViewController alloc]ini ...
- pyqt4学习之一:搭建环境和入门
还在继续写Python小工具,想起之前用Tkinter被坑得半死,决定换个框架写UI,又想顺便了解一下qt,就学习一下pyqt4 搭建环境 win:现在安装包 http://www.riverbank ...
- Spring_通过注解配置 Bean(1)
beans-annotation.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns ...