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; ...
随机推荐
- scrapy工程创建及pycharm运行
1.通过命令行创建scrapy工程项目 scrapy startproject (工程名) scrapy startproject myxml 2.利用爬虫模板设置爬虫文件 在这个过程中我们可以先利用 ...
- 10分钟让你的站点也支持Markdown
Markdown简介 Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.Markdown 的语法十分简单,常用的标记符号也不超过十个,这种相对于 ...
- KMS Event LOG
The 12290 event entry gives a significant amount of information that can be used to figure out what ...
- 【我的Android进阶之旅】如何去除ListView中Header View、Footer View中的分割线
最近的项目中给ListView 加入了一个Header View之后,发现Header View的下方也有了分割线,很难看,UI要求将Header View的分割器去掉,好吧.现在就来说一说如何如何去 ...
- mysql以下c连接mysql数据库
1.安装sudo yum install mysql-devel 安装组件和库 2. #include <stdio.h> #include <stdlib.h> #incl ...
- golang redis的模式订阅
c := redisPool.Get() psc := redis.PubSubConn{c} psc.PSubscribe("aa*") for { switch v := ps ...
- Nordic Blue Tooth
一 . nordic BLE4.0 1.开发nordic的应用需要安装支持keil的pack库和插件 2.nordic的SDK很完整,实例涵盖了几乎所有的应用 https://www.nordicse ...
- C语言-随机数
C语言使用rand()函数产生随机数, 使用rand()函数之前要先使用srand(time(0)), 以当前时间作为种子, 否则产生的随机数将不会变化. #include <stdio.h&g ...
- Python一些常用模块
阅读目录 一: collections模块 二: time,datetime模块 三: random模块 四: os模块 五: sys模块 六: json,pickle 七: re正则模块 八:re模 ...
- shiro 拦截器
参考