金狮镖局 Design By www.egabc.com
AngularJs被用来开发单页面应用程序(SPA),利用AJAX调用配合页面的局部刷新,可以减少页面跳转,从而获得更好的用户体验。Angular的ngView及其对应的强大路由机制,是实现SPA应用的核心模块。本文所说的页面切换指的就是这个路由机制,即根据不同的url展示不同的视图。
前端开发中,为了对列表项进行快捷操作,有时就添个按钮来简单实现。但是,有时会发现按钮影响美观,甚至影响列表行的布局。稍在网上搜索无果,而写此仿苹果滑屏删除控件。
依赖项:angularJS、jQuery
测试浏览器:Chrome、IE11、手机浏览器
原先列表项代码:
<div class="row-class" ng-repeat="item in list"> 这是整行显示的内容 </div>
开发目标:
<div class="row-class" ng-repeat="item in list" slide-delete text="删除" ondelete="ondelete(item)"> 这是整行显示的内容 </div>
首先,要写个angular指令:
myapp.directive('slideDelete', function() { return { restrict: 'AE', scope: { text: "@", ondelete: "&" }, link: function (scope, element, attrs) { var w = $(element).outerWidth ();//应显示的宽度 var h = $(element).outerHeight();//应显示的高度 //按钮宽度 var btn_w = 60; //设计按钮: scope.btn = $('<div style="position:absolute;z-index:5998;right:0;top:0;width:'+btn_w+'px;height:'+h+'px;color:#fff;background-color:#900;text-align:center;padding-top:10px">'+(scope.text||'删除')+'</div>'); //改造行,用一个绝对定位div将内容包裹起来 $(element).contents().wrapAll('<div new_box style="position:absolute;z-index:5999;left:0;top:0;width:'+w+'px;height:'+h+'px;background-color:#fff;"></div>'); //添加按钮: $(element).css({overflow:"hidden", position:"relative", "z-index":5999}).append(scope.btn) //滑屏功能 .slideable({ getLeft: function(self){return self.children(":first-child").position().left;}, setLeft: function(self, x){ self.children(":first-child").css({left: x<-btn_w && -btn_w || x<0 && x || 0});}, onslide: function(self, x){ scope.open = x < -btn_w / 2; self.css("z-index", scope.open && 6001 || 5999); //背景,点击收起 var bk = $.fixedBackground(6000, scope.open); scope.open && bk.data("self", self).click(function(){ var self = bk.data("self"); $.fixedBackground(6000, false); self && self.css("z-index", 5999).children(":first-child").animate({left: 0},100); }); self.children(":first-child").animate({left: scope.open "htmlcode">(function($){ $.fn.slideable = function(options){ var self = this; self.options = options; self.left = 0; self.down = 0; self.pressed = false; self.bindobj = options.bindobj || self; self.bindobj.bind("mousedown",function(event){ onmousedown(self, event); }) self.bindobj.bind("mousemove",function(event){ onmousemove(self, event); }) self.bindobj.bind("mouseup" ,function(event){ onmouseup (self, event); }) self.bindobj[0].addEventListener('touchstart', function(event) { onmousedown(self, {screenX: event.changedTouches[0].pageX}); }) self.bindobj[0].addEventListener('touchmove' , function(event) { onmousemove(self, {screenX: event.changedTouches[0].pageX}); }) self.bindobj[0].addEventListener('touchend' , function(event) { onmouseup (self, {screenX: event.changedTouches[0].pageX}); }) return this; } function onmousedown(self, event){ self.down = event.screenX; self.options.onmousedown && self.options.onmousedown(self); self.left = self.options.getLeft && self.options.getLeft(self) || 0; self.pressed = true; } function onmousemove(self, event){ self.pressed && self.options.setLeft && self.options.setLeft(self, self.left + event.screenX - self.down); } function onmouseup(self, event){ self.pressed = false; self.left += event.screenX - self.down; self.options.onslide && self.options.onslide(self, self.left); } //背景功能 $.fixedBackground = function(z_index, b_show){ var bk = $('#fixed-background-'+z_index+''); if(!b_show)return bk && bk.remove(); if(!(bk && bk.length>0)){ bk = $('<div id="fixed-background-'+z_index+'" style="position:fixed;z-index:'+z_index+';left:0;top:0;right:0;bottom:0;background-color:rgba(0,0,0,0)">'); $("body").append(bk); } return bk; } })(jQuery);关于上述代码给大家介绍的AngularJS仿苹果滑屏删除控件的相关代码,都是小编测试过的,可以放心安全使用。
标签:
angularjs控件
金狮镖局 Design By www.egabc.com
金狮镖局
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com
暂无AngularJS仿苹果滑屏删除控件的评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年09月24日
2024年09月24日
- 范文芳1999-真心话电影原声带[HYPE][WAV+CUE]
- 袁培华.1990-我写不出一首情歌给我最爱的你【可登】【WAV+CUE】
- 群星.2007-歌林10年流行岁月12CD【歌林】【WAV+CUE】
- 软硬天师.2006-LONG.TIME.NO.SEE【金牌大风】【WAV+CUE】
- 卓依娜姆《美人谋 网剧影视原声带》[FLAC/分轨][162.27MB]
- 国风大师纯音系列《蒋倩 :古筝演奏家》1CD[MP3][160.7MB]
- 国风大师纯音系列《王中山古筝》1CD[MP3][519MB]
- 徐玮1986-走自己的路[台湾复刻版][WAV+CUE]
- 黄思婷2004-情缘[豪记唱片][WAV+CUE]
- 群星《左耳·听见爱情》星文唱片[WAV+CUE]
- 陈美玲.1987-孤单的心【EMI百代】【WAV+CUE】
- 黄乙玲.2005-甲你作伴【亚律音乐】【WAV+CUE】
- 张雨生.1997-口是心非【丰华】【WAV+CUE】
- 群星《右耳·聆听私语》星文唱片[WAV+CUE]
- VitoCadonau-ramur-encasaveglia(2024)[24-44,1]FLAC