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.滚动方向 可以左右,也可以上下 directionattribute. The possible values are horizontal(default) or vertical.
 5.单项的 item-width or item-height  竖向滚动,只能调节横宽;横的话,这能调节高
    6.swipeable属性 可以用手滚动
  7.auto-refresh 数据自动刷新
  8.auto-scroll-ratio 滚动的比率

控制器方法:(angularjs)

用法:可以用var=myCarousel 命名,用此名称,在控制器中调用
1.next下一个:myCarousel.next({ animation: "none", callback: function(){// Fired when the scroll is done }});
2.first(options)last(options)
3.setActiveCarouselItemIndex(index, options)指定活跃的当前项
4.如果用js添加<ons-carousel-item>必须用 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():滚动返回监听
事件方法:demo:
<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懒加载的用法

第一大点:懒加载依赖一个代理加载所有数据:Delegate object in AngularJS用angularJS
$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 the initial 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">

相关方法:1. show(options)hide(options)Shows or hides the dialog. You can specify animations and callback in the options parameter to get more control.
  • isShown()Returns true 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.

不同的图标库,提供的图标不一样
Using Font Awesome:<ons-iconicon="fa-angle-left"></ons-icon>
Using Ionicons: <ons-iconicon="ion-angle-left"></ons-icon>

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: dragdragleftdragrightdragupdragdown 拖 向左右上下
  • Hold gestures: holdrelease 常安
  • Swipe gestures: swipeswipeleftswiperightswipeupswipedown 轻扫
  • Tap gestures: tapdoubletap 点击
  • Pinch gestures: pinchpinchinpinchout 捏合
  • 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
1.入新页面add a new page to the stack, use 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>
  返回安卓ios:myNavigator.popPage() 安卓设备返回,自动获取 navigator’s 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: slideliftfadeand none.
navigator.pushPage("page2.html", { animation: "slide" }):

过度动画 也能定制
3.方法:navigator.getCurrentPage()得到当前页面
navigator.getPages()得到Returns an array of page objects from the navigator.
navigator.insertPage(index, page, options)插入页面
navigator.replacePage(page, options)替换页面Replaces the current page with the specified one
<ons-navigator> has several events defined: prepushpostpushprepoppostpop
14.ons-sliding-menu 滑动菜单
1.主要属性:
menu-page 滑动菜单
main-page 主页面
swipeable 手滑动
swipe-target-width 滑动宽度
max-slide-distance 菜单宽度
direction 方向"left" and "right"
type reveal (default), push and overlay
2.事件
setMainPage(pageUrl, [options])
setMenuPage(pageUrl, [options])
openMenu([options])
closeMenu([options])
toggleMenu([options])
<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个

1.主要属性:ons-tab
page 添加页面
icon  图标
active-icon 活跃图标
label tab 中间添加label
active Boolean设置活跃
<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>
hide-tabs 显示Boolean
animation "none""slide" and "fade". Default is "none". Optional.
position "bottom" and "top"
2.事件:
There are prechangepostchange 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)

getActiveTabIndex()
on(eventName, listener)
16.ons-popover信息提示框
1.常用属性
direction"up", "down", "left" and "right". 
cancelable 点击取消
animation "none" or "fade"
mask-color background mask
2.常用方法
show(target, [options])
hide([options])
isShown()
destroy()
setCancelable(cancelable)
<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工具条

1. <ons-toolbar> or <ons-bottom-toolbar>
 toolbar is divided into 3 sections (left, center, and right)
2.<ons-back-button>
<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.其他的控件

1.ons-if-orientation portrait and landscape 横屏树屏
2.ons-if-platform平台判断

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 全局的

ready 等Onsen UI 初始化后,调用此方法
enableAutoStatusBarFill() 状态栏填充
disableAutoStatusBarFill() 状态栏不填充
findParentComponentUntil(name, [dom])找父视图DOM
<divons-keyboard-active> This will only be displayed if the software keyboard is open.</div><divons-keyboard-inactive> There is also a component that does the opposite.</div>

onSenUI 常用UI组件 笔记相关推荐

  1. Taro-ui 常用 UI 组件库说明

    Taro-ui 常用 UI 组件库说明 https://taro-ui.jd.com/#/docs/introduction 安装 npm install -g @tarojs/cli taro in ...

  2. 3.Android学习之常用UI组件(一)

    目录 3.常用UI组件(一) 1.文本类组件 1-1.文本框(TextView) 1-2.编辑框(EditText) 2.按钮类组件 2-1.普通按钮(Button) 2-2.图片按钮(ImageBu ...

  3. 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 组件库 ...

  4. react常用ui组件库

    前端常用组件库 移动端和pc端适配:react+chakre-ui组件库+recoil状态管理+react-router-dom+typescript https://chakra-ui.com/do ...

  5. VUE常用UI组件插件及框架-vue前端UI框架收集

    UI组件及框架 element - 饿了么出品的Vue2的web UI工具套件 mint-ui - Vue 2的移动UI元素 iview - 基于 Vuejs 的开源 UI 组件库 Keen-UI - ...

  6. 前端开发常用UI组件库(vue、react)

    pc端 Ant Design Ant Design是基于 Ant Design 设计体系的 React UI 组件库 Element Element是基于 Vue 2 的UI组件库 Element+ ...

  7. RN常用UI组件技术选型

    rn默认提供的控件比较基础,我们想要达到一个开箱即用的体验来构建常用app的UI,不可避免的需要用到自定义的组件库. 那么对于快速开发来说,我们选择一个不错的第三方组件库就是一件很重要的事.经过调研, ...

  8. vue 常用ui组件

    vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cn de ...

  9. vue 常用ui组件库

    vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cn de ...

最新文章

  1. 音乐产业碰撞人工智能,这次擦出了怎样的新火花?
  2. REST API 支持方式
  3. Sql Server 2005的1433端口打开和进行远程连接
  4. 18B树、B++树和Trie树
  5. 用ADOQuery创建SQL Server数据库,并创建表结构、存储过程和视图
  6. jstack 脚本 自动日志_运维老司机又翻车, 居然没用过日志切割Logrotate
  7. 个人博客存在的三种形式
  8. 云桌面优缺点_云桌面中VDI架构有什么优势和劣势?
  9. makefile的简单编写
  10. Opencv实现多张JPG转GIF
  11. 守望先锋为何如此火爆
  12. yarn : 无法加载文件 C:\Users\wangxin67\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.mic
  13. 《C Primer Plus》学习笔记—第9章
  14. ASP.NET的图片上传和显示
  15. python计算模型psi_模型稳定度指标PSI与IV
  16. 【HTML + CSS】模仿腾讯云页面——初步实现
  17. Linux添加开机自启动应用
  18. Pytorch实战:用经典网络实现猫狗大战
  19. 阿拉伯数字转化为中文的数字(金额)
  20. JavaScript倒计时牌

热门文章

  1. ME863手机(android)下安装backtrack 5
  2. 5-7万资金,可以创业吗?
  3. 下载和攻略之青空下的约定 この青空に約束を
  4. DNSPod十问梁凯:并购街电,共享充电宝行业的逆袭传奇
  5. 51、基于51单片机洗衣机控制系统(带水位)系统设计(程序+原理图+PCB源文件+Proteus仿真+参考论文+开题报告+任务书+流程图+元器件清单等)
  6. 美联储的传统的货币政策工具
  7. 嵌入式linux 国嵌,[嵌入式Linux学习]国嵌嵌入式视频1
  8. 中国最牛的5位【IT界大佬】30岁在干嘛?
  9. 量化新手初识H-M模型
  10. 【技术分享】Ubuntu下使用微信教程