onSenUI 常用UI组件 笔记
1.carousel 轮播图的用法总结
界面方法:
1.用于满屏
<ons-carousel fullscreen swipeable overscrollable auto-scroll> <ons-carousel-item> Carousel Item 1 </ons-carousel-item> <ons-carousel-item> Carousel Item 2 </ons-carousel-item></ons-carousel>
2. <ons-carousel-cover>用于顶部显示的内容,一直在顶部
3.initial-index 初始化显示的项目
4.滚动方向 可以左右,也可以上下 direction
attribute. The possible values are horizontal
(default) or vertical
.
5.单项的 item-width
or item-height
竖向滚动,只能调节横宽;横的话,这能调节高
6.swipeable属性 可以用手滚动
7.auto-refresh 数据自动刷新
8.auto-scroll-ratio
滚动的比率
控制器方法:(angularjs)
first(options)
, last(options)
auto-refresh或refresh()者刷新
5.事件方法:postchange滚动变化的过程
carousel
: Contains the carousel object.所有项activeIndex
: The index of the current active item.当前活跃项lastActiveIndex
: The index of the previous active item.下一个活跃项- waitToReturn():滚动返回监听
<pre name="code" class="javascript">app.controller("MyController", function($q, $scope) {$scope.status = "Init";ons.ready(function() {carousel.on('overscroll', function(event) {var deferred = $q.defer();$scope.status = "Overscroll " + event.direction;$scope.$apply();event.waitToReturn(deferred.promise);window.setTimeout(function() {deferred.resolve();$scope.status = "Finish";}, 1500);})});
2.ons-lazy-repeat懒加载的用法
$scope.MyDelegate = {configureItemScope: function(index, itemScope) {console.log("Created item #" + index);itemScope.item = {name: 'Item #' + (index + 1)};},calculateItemHeight: function(index) {return 40;},countItems: function() {return 10000000;},destroyItemScope: function(index, scope) {console.log("Destroyed item #" + index);}
};
configureItemScope
contains the information about the items, which can be dynamically created or loaded from a array of items.(加载数据)calculateItemHeight
returns the height of an item. It could be different for every item.(每项的高)countItems
returns the total number of items in the list.(展示的项数)destroyItemScope
is an optional method that will be triggered everytime an item is unloaded. This can be used to destroy elements and remove event listeners in order to avoid memory leaks.(没显示的项目,毁掉)
第二大点:动态的加载数据 angularJS
configureItemScope: function(index, itemScope) {if (!itemScope.item) {itemScope.canceler = $q.defer();itemScope.item = {title: 'Item #' + (index + 1),label: '',desc: '',rand: Math.random()};$http.get('https://baconipsum.com/api/?type=meat-and-filler&sentences=1', {timeout: itemScope.canceler.promise}).success(function(data) {itemScope.item.desc = data[0];itemScope.item.label = data[0].substr(0, data[0].indexOf(" ")) + 'bacon';}).error(function() {itemScope.item.desc = 'No bacon lorem ipsum';itemScope.item.label = 'No bacon';});}
},
destroyItemScope: function(index, itemScope) {itemScope.canceler.resolve();
}
3.Pull Hook<ons-pull-hook>
用于an <ons-page>
or an <ons-scroller>
<ons-pull-hook ng-action="load($done)" var="loader"><span ng-switch="loader.getCurrentState()"><span ng-switch-when="initial"><ons-icon size="35px" icon="ion-arrow-down-a"></ons-icon> Pull down to refresh</span><span ng-switch-when="preaction"><ons-icon size="35px" icon="ion-arrow-up-a"></ons-icon> Release to refresh</span><span ng-switch-when="action"><ons-icon size="35px" spin="true" icon="ion-load-d"></ons-icon> Loading data...</span></span>
</ons-pull-hook>
initial
: default state before any user interaction, the element remains in this status until it’s totally dragged down, going beyond its height limit.()preaction
: if the component is in this state it will execute its action if it’s released. It’s still possible to cancel the action by dragging the page up again.action
: the pull hook will be in this state while its action is running. After the$done
function is called it will return to theinitial
state.ng-action
: used to specify custom behavior when the page is pulled down. A$done
function is available to tell the component that the action is completed.height
: specifies the height of the component. When pulled down further than this value it will switch to the “preaction” state. The default value is “64px”.
4.Alert Dialog<ons-alert-dialog>有三种
第一种:Alert dialog ons.notification.alert() 一个button ,一段提醒文字
$scope.alert = function(material) {ons.notification.alert({message: 'An error has occurred!',modifier: material ? 'material' : undefined});}
第二种:Confirm dialogons.notification.confirm()
but can have multiple buttons.两个按钮
$scope.confirm = function(material) {var mod = material ? 'material' : undefined;ons.notification.confirm({message: 'Are you sure you want to continue?',modifier: mod,callback: function(idx) {switch (idx) {case 0:ons.notification.alert({message: 'You pressed "Cancel".',modifier: mod});break;case 1:ons.notification.alert({message: 'You pressed "OK".',modifier: mod});break;}}});}
第三种:Prompt dialogons.notification.prompt()
有输入框
$scope.prompt = function(material) {var mod = material ? 'material' : undefined;ons.notification.prompt({message: "Please enter your age",modifier: mod,callback: function(age) {ons.notification.alert({message: 'You are ' + parseInt(age || 0) + ' years old.',modifier: mod});}});}
也可以自己定义创建:
<pre name="code" class="javascript"><ons-template id="alert-dialog.html">
<ons-alert-dialog var="alertDialog"><div class="alert-dialog-title"><strong style="color: #ff3333">Critical Alert!</strong></div><div class="alert-dialog-content">An error has occurred!</div><div class="alert-dialog-footer"><button class="alert-dialog-button" ng-click="alertDialog.hide(); alertDialog.show()">OK</button></div>
</ons-alert-dialog>
</ons-template><script>
ons.ready(function() {ons.createAlertDialog('alert-dialog.html').then(function(alertDialog) {alertDialog.show();});
});
</script>
5. Dialog 自定义dialog
为了显示dialog,必须创建一个模板包含<ons-dialog>模板
template,然后通过ons.createDialog()函数创建
show()调用这个dialog
<ons-template id="dialogcontent.html">
show(options)
, hide(options)
Shows or hides the dialog. You can specify animations
and callback
in the options
parameter to get more control.
isShown()
Returnstrue
if the dialog is shown.判断是否在显示destroy()
Hides the dialog and remove all related DOM elements.销毁setDisabled(disabled)
,isDisabled()
Makes the dialog disable and prohibits any interaction from the user.禁用setCancelable(cancelable)
,isCancelable()
Set the dialog cancelable, which means it will close automatically when pressing the back button.
<ons-dialog>Any HTML code here</ons-dialog>
</ons-template>
<script>
ons.ready(function() {ons.createDialog('dialogcontent.html').then(function(dialog) {dialog.show();});
});
</script>
<ons-template id="login.html"><ons-dialog var="dialog" cancelable><ons-toolbar inline><div class="center">Login</div></ons-toolbar><p><input placeholder="Username" id="username" class="text-input"></p><p><input type="password" placeholder="Password" id="username" class="text-input"></p><p><ons-button modifier="large" ng-click="dialog.hide()">Sign in</ons-button></p></ons-dialog>
</ons-template>
5. button usingmodifier(样式)
, should-spin(布尔值)
, animation
and disabled
attributes. modifier
6.Text input
Text input <inputclass="text-input"id="my-input"> 输入一条文字
Text area <textareaclass="textarea"id="my-textarea"></textarea> 一大段段文字
Search input <inputtype="search"class="search-input">搜索框
Check box and radio button 多选框,单选框
Check box and radio button are provided as CSS components. Therefore, use the following HTML snippet to display each component.
<label class="checkbox">
<input type="checkbox"><div class="checkbox__checkmark"></div><span class="ons-checkbox-inner"></span> </label>
<label class="radio-button"><input type="radio"><div class="radio-button__checkmark"></div>
</label>
7.Grid <ons-row>
and <ons-col> 用法见下面的例子:
<ons-row align="bottom"><ons-col><div class="Demo">This cell should be bottom-aligned.</div></ons-col><ons-col><div class="Demo">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do euismod tempor incididunt ut larbore et dolore magna aliqua.</div></ons-col><ons-col><div class="Demo">This cell should be bottom-aligned.</div></ons-col></ons-row>
8.ons-iconOnsen UI offers over 400 icons provided by Font Awesome and over 500 icons by Ionicons.
9.ons-gesture-detector手势
use ng-gestureeventname
if you prefer an AngularJS way.
<ons-gesture-detector ng-swipeleft="doSomething()"><div id="detect-area" style="width: 100px; height: 100px;">Swipe Here</div>
</ons-gesture-detector>
Following gestures are supported.
- Drag gestures:
drag
,dragleft
,dragright
,dragup
,dragdown 拖 向左右上下
- Hold gestures:
hold
,release 常安
- Swipe gestures:
swipe
,swipeleft
,swiperight
,swipeup
,swipedown 轻扫
- Tap gestures:
tap
,doubletap 点击
- Pinch gestures:
pinch
,pinchin
,pinchout 捏合
- Other gestures:
touch轻触
,transform变形
,rotate旋转
10.ons-keyboard-active 键盘响应
<div ons-keyboard-active>This will only be displayed if the software keyboard is open.
</div>
<div ons-keyboard-inactive>There is also a component that does the opposite.
</div>
11 List 列表 Onsen UI supports scrollable lists by using <ons-list>
and <ons-list-item>
tags.
1.ons-list-header
<ons-list><ons-list-header>Header Text</ons-list-header><ons-list-item>Item</ons-list-item><ons-list-item>Item</ons-list-item>
</ons-list>
2.ons-list modifier可修改
12.ons-modal 蒙版 可以在蒙版上加东西show()hide()getDeviceBackButtonHandler()
<ons-modal var="modal"><ons-icon icon="ion-load-c" spin="true"></ons-icon><br><br> Please wait.<br>Closing in 2 seconds.
</ons-modal>
13 Page Navigation
<ons-navigator>
is a page stack manager + transition animator 堆栈管理 加 动画 没有内容 是个顶部controller 加nav 用 add a toolbar on top of the page
pushPage()也可以传递参数
<span style="font-size:18px;"><ons-navigator var="myNavigator"></ons-navigator>
<script>
var options = {animation: 'slide', // What animation to useonTransitionEnd: function() {} // Called when finishing transition animation
};
myNavigator.pushPage("page2.html", options);
</script></span>
传递参数
<span style="font-size:14px;">myNavigator.pushPage("page2.html", {data: {param1: 'foo',param2: 'bar'}}).then(function(page) {console.log("Parameter passed: ", page.data)})</span>
popPage()
如果ihone的
<ons-toolbar><div class="left"><ons-if platform="ios"><ons-back-button>Back</ons-back-button></ons-if></div><div class="center">Page Title</div>
</ons-toolbar>
<ons-navigator var="myNavigator"></ons-navigator><script>myNavigator.popPage();</script>
2.动画效果4种pushPage()
and popPage()
method can specify the following animation patterns: slide
, lift
, fade
and none
.
navigator.pushPage("page2.html", { animation: "slide" }):
page
objects from the navigator.
<ons-navigator>
has several events defined: prepush
, postpush
, prepop
, postpop
1.主要属性:
<span style="font-size:14px;"><ons-sliding-menu main-page="page1.html" menu-page="menu.html" side="left" max-slide-distance="250px" var="menu">
</ons-sliding-menu>
<ons-template id="page1.html"><ons-page><ons-toolbar><div class="left"><ons-toolbar-button ng-click="menu.toggleMenu()"><ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"></ons-icon></ons-toolbar-button></div><div class="center">Page 1</div></ons-toolbar><p style="text-align: center; color: #999; padding-top: 100px;">Page1 Contents</p></ons-page>
</ons-template>
<ons-template id="page2.html"><ons-page><ons-toolbar><div class="left"><ons-toolbar-button οnclick="menu.toggleMenu()"><ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"></ons-icon></ons-toolbar-button></div><div class="center">Page 2</div></ons-toolbar><p style="text-align: center; color: #999; padding-top: 100px;">Page2 Contents</p></ons-page>
</ons-template>
<ons-template id="menu.html"><ons-list><ons-list-item modifier="chevron" οnclick="menu.setMainPage('page1.html', {closeMenu: true})">page1.html</ons-list-item><ons-list-item modifier="chevron" οnclick="menu.setMainPage('page2.html', {closeMenu: true})">page2.html</ons-list-item></ons-list>
</ons-template></span>
15.ons-tabbar, ons-tab <ons-tabbar>
component and <ons-tab>
3个-5个
ons-tab
<span style="font-size:14px;"><ons-tabbar position="top"><ons-tab page="page1.html" label="Page 1" icon="fa-square" active="true"></ons-tab><ons-tab page="page2.html" label="Page 2" icon="fa-square"></ons-tab><ons-tab page="page3.html" label="Page 3" icon="fa-square"></ons-tab>
</ons-tabbar></span>
<span style="font-size:14px;"><ons-tab page="page.html"><div ons-tab-active></div><div ons-tab-inactive></div></span><span style="font-size: 16px;">
</ons-tab></span>
<ons-tabbar>
"none"
, "slide"
and "fade"
. Default is "none"
. Optional.
"bottom"
and "top"
There are
prechange
, postchange
and reactive
events in <ons-tabbar>
.
<span style="font-size:14px;">ons.ready(function() {var myTabbar = document.querySelector("ons-tabbar")myTabbar.addEventListener("prechange", function(e) {if (e.index == 1) {e.cancel();}})
})</span>
setActiveTab(index, options)
1.常用属性
<span style="font-size:14px;"><script>
ons.ready(function() {ons.createPopover('popover.html').then(function(popover) {popover.show('#mybutton'); });
});
</script>
<script type="text/ons-template" id="popover.html"><ons-popover cancelable><p style="text-align: center; opacity: 0.5;">This popover will choose which side it's displayed on automatically.</p></ons-popover>
</script></span>
17.ons-toolbar工具条
<ons-toolbar>
or <ons-bottom-toolbar>
<span style="font-size:14px;"><ons-toolbar><div class="left"><ons-toolbar-button>Button</ons-toolbar-button></div><div class="center">Title</div><div class="right"><ons-toolbar-button><ons-icon icon="ion-navion" size="28px"></ons-icon></ons-toolbar-button></div>
</ons-toolbar></span>
18.其他的控件
Either "opera", "firefox", "safari", "chrome", "ie", "android", "blackberry", "ios" or "windows". |
3.ons-loading-placeholder下载占位符
<span style="font-size:14px;"><div ons-loading-placeholder="page.html">Loading...
</div></span>
4.ons-template模板
5.ons 全局的
enableAutoStatusBarFill() 状态栏填充
onSenUI 常用UI组件 笔记相关推荐
- Taro-ui 常用 UI 组件库说明
Taro-ui 常用 UI 组件库说明 https://taro-ui.jd.com/#/docs/introduction 安装 npm install -g @tarojs/cli taro in ...
- 3.Android学习之常用UI组件(一)
目录 3.常用UI组件(一) 1.文本类组件 1-1.文本框(TextView) 1-2.编辑框(EditText) 2.按钮类组件 2-1.普通按钮(Button) 2-2.图片按钮(ImageBu ...
- Vue UI 组件库(移动端常用 UI 组件库,PC 端常用 UI 组件库,Element UI基本使用,Element UI按需引入)
文章目录 Vue UI 组件库 7.1 移动端常用 UI 组件库 7.2 PC 端常用 UI 组件库 7.3 Element UI基本使用 7.4 Element UI按需引入 Vue UI 组件库 ...
- react常用ui组件库
前端常用组件库 移动端和pc端适配:react+chakre-ui组件库+recoil状态管理+react-router-dom+typescript https://chakra-ui.com/do ...
- VUE常用UI组件插件及框架-vue前端UI框架收集
UI组件及框架 element - 饿了么出品的Vue2的web UI工具套件 mint-ui - Vue 2的移动UI元素 iview - 基于 Vuejs 的开源 UI 组件库 Keen-UI - ...
- 前端开发常用UI组件库(vue、react)
pc端 Ant Design Ant Design是基于 Ant Design 设计体系的 React UI 组件库 Element Element是基于 Vue 2 的UI组件库 Element+ ...
- RN常用UI组件技术选型
rn默认提供的控件比较基础,我们想要达到一个开箱即用的体验来构建常用app的UI,不可避免的需要用到自定义的组件库. 那么对于快速开发来说,我们选择一个不错的第三方组件库就是一件很重要的事.经过调研, ...
- vue 常用ui组件
vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cn de ...
- vue 常用ui组件库
vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cn de ...
最新文章
- 音乐产业碰撞人工智能,这次擦出了怎样的新火花?
- REST API 支持方式
- Sql Server 2005的1433端口打开和进行远程连接
- 18B树、B++树和Trie树
- 用ADOQuery创建SQL Server数据库,并创建表结构、存储过程和视图
- jstack 脚本 自动日志_运维老司机又翻车, 居然没用过日志切割Logrotate
- 个人博客存在的三种形式
- 云桌面优缺点_云桌面中VDI架构有什么优势和劣势?
- makefile的简单编写
- Opencv实现多张JPG转GIF
- 守望先锋为何如此火爆
- yarn : 无法加载文件 C:\Users\wangxin67\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.mic
- 《C Primer Plus》学习笔记—第9章
- ASP.NET的图片上传和显示
- python计算模型psi_模型稳定度指标PSI与IV
- 【HTML + CSS】模仿腾讯云页面——初步实现
- Linux添加开机自启动应用
- Pytorch实战:用经典网络实现猫狗大战
- 阿拉伯数字转化为中文的数字(金额)
- JavaScript倒计时牌
热门文章
- ME863手机(android)下安装backtrack 5
- 5-7万资金,可以创业吗?
- 下载和攻略之青空下的约定 この青空に約束を
- DNSPod十问梁凯:并购街电,共享充电宝行业的逆袭传奇
- 51、基于51单片机洗衣机控制系统(带水位)系统设计(程序+原理图+PCB源文件+Proteus仿真+参考论文+开题报告+任务书+流程图+元器件清单等)
- 美联储的传统的货币政策工具
- 嵌入式linux 国嵌,[嵌入式Linux学习]国嵌嵌入式视频1
- 中国最牛的5位【IT界大佬】30岁在干嘛?
- 量化新手初识H-M模型
- 【技术分享】Ubuntu下使用微信教程