Weex 初始

摘要:
','okTitle':'ok','cancelTitle':'cancel'},function{self.toast;});}}}效果图4.动画&

1.一旦数据和模板绑定,数据的变化会立即体现在前台的变化

<template>
  <container>
    <text style="font-size: {{size}}">{{title}}</text>
  </container>
</template>

<script>module.exports ={
    data: {
      size: 48,
      title: 'Alibaba Weex Team'}
  }
</script>
<template>
  <container>
    <text style="font-size: {{title.size}}">{{title.value}}</text>
  </container>
</template>

<script>module.exports ={
    data: {
      title: {
        size: 48,
        value: 'Alibaba Weex Team'}
    }
  }
</script>

2.样式类

<template>
  <container>
    <text style="font-size: {{fontSize}};">Alibaba</text>
    <text class="large {{textClass}}">Weex Team</text>
  </container>
</template>
<style>.large {font-size:32;}.highlight {color:#ff0000;}
</style>
<script>module.exports ={
    data: {
      fontSize: 32,
      textClass: 'highlight'}
  }
</script>

3.事件

<template>
  <container>
    <text onclick="toggle">Toggle</text>
    <image  class="thumb"src="http://alibaba.github.io/weex/img/weex_logo_blue@3x.png"if="{{shown}}"></image>
  </container>
</template>

<script>module.exports ={
    data: {
      shown: true},
    methods: {
      toggle: function() {
        this.shown = !this.shown
      }
    }
  }
</script>

<style>.thumb {width:100;height:100; }
</style>
<template>
  <scroller>
    <wxc-panel title="Toast"type="primary">
      <wxc-button type="primary"onclick="{{toast}}"value="Toast"></wxc-button>
    </wxc-panel>

    <wxc-panel title="Dialog"type="primary">
      <wxc-button type="success"onclick="{{alert}}"value="Alert"style="margin-bottom: 20px;"></wxc-button>
      <wxc-button type="primary"onclick="{{confirm}}"value="Confirm"style="margin-bottom: 20px;"></wxc-button>
      <wxc-button type="warning"onclick="{{prompt}}"value="Prompt"></wxc-button>
    </wxc-panel>
  </scroller>
</template>

<script>require('weex-components');
  module.exports ={
    data: {},
    methods: {
      toast: function(msg, duration) {
        if(!msg || typeofmsg !== 'string') {
          msg = 'I am Toast show!';
        }

        duration =duration || 2;
        this.$call('modal', 'toast', {
          'message': msg,
          'duration': duration
        });
      },
      alert: function(msg, okTitle, cancelTitle) {
        varself = this;
        if(!msg || typeofmsg !== 'string') {
          msg = "I am Alert!";
        }
        this.$call('modal', 'alert', {
          'message': msg,
          'okTitle': okTitle,
          'cancelTitle': cancelTitle
        }, function() {
          self.toast("Click Alert OK Bnt!!");
        });
      },
      confirm: function(msg, okTitle, cancelTitle) {
        varself = this
        if(!msg || typeofmsg !== 'string') {
          msg = "I am Confirm!";
        }

        okTitle =okTitle || "OK";
        cancelTitle =cancelTitle || "Cancel";
        this.$call('modal', 'confirm', {
          'message': msg,
          'okTitle': okTitle,
          'cancelTitle': cancelTitle
        }, function(result) {
          self.toast("Click Confirm  " +result);
        });
      },
      prompt: function() {
        varself = this;
        this.$call('modal', 'prompt', {
          'message': 'I am Prompt!',
          'okTitle': 'ok',
          'cancelTitle': 'cancel'}, function(result) {
          self.toast("Click Prompt  " +result);
        });
      }
    }
  }
</script>

<style>
</style>

效果图

Weex 初始第1张

4.动画

<template>
  <div>
    <wxc-panel title="Transform"type="primary">
      <wxc-button value="Rotate"onclick="{{rotate}}"type="primary"size="middle"></wxc-button>
      <wxc-button value="Scale"onclick="{{scale}}"type="primary"size="middle"style="margin-top:12px;"></wxc-button>
      <wxc-button value="Translate"onclick="{{translate}}"type="primary"size="middle"style="margin-top:12px;"></wxc-button>
      <wxc-button value="Transform"onclick="{{transform}}"type="success"size="middle"style="margin-top:12px;"></wxc-button>
    </wxc-panel>

    <wxc-panel title="Others"type="primary">
      <wxc-button value="BgColor"onclick="{{color}}"type="primary"size="middle"></wxc-button>
      <wxc-button value="Opacity"onclick="{{opacity}}"type="primary"size="middle"style="margin-top:12px;"></wxc-button>
      <wxc-button value="All"onclick="{{composite}}"type="success"size="middle"style="margin-top:12px;"></wxc-button>
    </wxc-panel>

    <div id="block"class="block"style="transform-origin:{{transformOrigin}}">
      <text class="block-txt">Anim</text>
    </div>
  </div>
</template>

<script>require('weex-components');
  module.exports ={
    data: {
      transformOrigin: 'center center',
      current_rotate: 0,
      current_scale: 1,
      current_color: '#FF0000',
      current_opacity: 1,
      current_translate: '',
      current_transform: '',
      isStop: true},
    methods: {
      anim: function(styles, timingFunction, duration, callback) {
        this.$call('animation', 'transition', this._ids.block.el.ref, {
          styles: styles,
          timingFunction: timingFunction,
          duration: duration
        }, callback);
      },
      rotate: function() {
        varself = this;
        self.current_rotate += 90;
        self.anim({
          transform: 'rotate(' +self.current_rotate + 'deg)'}, 'ease-in-out', 500, function() {
          if(self.current_rotate === 360) {
            self.current_rotate = 0;
          }
          else{
            self.rotate();
          }
        });
      },
      translate: function() {
        this.current_translate = this.current_translate ? '': 'translate(50%, 50%)';
        this.anim({
          transform: this.current_translate
        }, 'ease-in', 500, function() {
        });
      },
      scale: function() {
        varself = this;
        self.current_scale =self.current_scale === 2 ?.5: 2self.anim({
          transform: 'scale(' +self.current_scale + ')'}, 'linear', 500, function() {
        });
      },
      transform: function() {
        varself = this;
        this.current_transform = this.current_transform ? '': 'rotate(45deg) scale(1.5)';
        this.anim({
          transform: this.current_transform,
          transformOrigin: 'left top'}, 'ease-out', 500, function() {
          if(self.current_transform !== '') {
            self.anim({
              transform: 'rotate(-90deg) scale(1.2)',
              transformOrigin: 'left top'}, 'ease-out', 500, function() {
            })
          }
          else{

          }
        });
      },
      composite: function() {
        varself = this;
        self.current_transform =self.current_transform ? '': 'rotate(45deg) scale(1.5) translate(50%, 50%)';
        self.current_color =self.current_color === '#F0AD4E' ? '#D9534F': '#F0AD4E';
        self.current_opacity =self.current_opacity === 1 ? 0.1: 1;
        this.anim({
          transform: this.current_transform,
          transformOrigin: 'left top',
          backgroundColor: self.current_color,
          opacity: self.current_opacity
        }, 'ease-out', 1000, function() {
        });
      },
      color: function() {
        varself = this;
        self.current_color =self.current_color === '#F0AD4E' ? '#D9534F': '#F0AD4E';
        self.anim({
          backgroundColor: self.current_color
        }, 'linear', 500, function() {
        });
      },
      opacity: function() {
        varself = this;
        self.current_opacity =self.current_opacity === 1 ? 0.1: 1;
        self.anim({
          opacity: self.current_opacity
        }, 'linear', 500, function() {
        });
      }
    }
  };
</script>

<style>.block {position:absolute;width:250px;height:250px;top:300px;left:400px;background-color:#F0AD4E;align-items:center;justify-content:center;
  }
  .block-txt {color:#FFFFFF;font-size:70px;
  }
</style>

免责声明:文章转载自《Weex 初始》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇学以致用二十六-----虚拟机磁盘空间清理vue-virtual-scroller下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

PowerDesigner 技巧【3】

  一、PowerDesigner导出所有SQL脚本:     一般的导出SQL脚本只需要下面两个步骤:   1、database->change current DBMS(选择需要导出的数据库类型);   2、database->generate database,点击确定即可,如下图所示:     我的PDM目录下面有很多包,直接导出S...

Android-Dialog

Android-Diaolog   对话框是提示用户做出选择或是输入额外信息的小窗口,通常不会占满整个屏幕,与用户进行交互   下面介绍一些Dialog对话框的创建方式:主要使用AlterDialog类进行创建,AlterDialog的构造方法被修饰文protected,因此无法在保外使用,所以要利用构建器 1.使用AlterDialog 构建器Build...

SWFUpload 按钮显示问题

问题: 今天遇到一个这样的问题,我用Vs2010打开用SWFUpload上传文件的网页时,按钮显示不出来,试了好多方法,终于被我找到了! 解决方法: 原来是vs2010自带的Asp.net Development Server 浏览的问题, 只要把网页发布到IIS上运行就没有问题了,记录下来,以防以后出现类似的问题!...

动态绑定事件的方法

<!doctype html> <html> <head> <meta charset = "utf-8" /> </head> <div id = "target"></div> <script> var div = document.getEle...

Qt 设置窗口属性setWindowFlags函数

Qt 设置窗口属性setWindowFlags函数 说明:setWindowFlags函数就是设置窗口属性,本博客主要分析此函数的参数 本博客转载CSDN博主「hjhomw」的原创文章。原文链接:https://blog.csdn.net/hejun_haitao/java/article/details/50815695 主要是记录一下项目中遇到的问题...

用css画图标

css3的属性 transform(转换) 用途很广泛,功能也很强大,为了熟悉它的各种转换方式(平移 translate,旋转 rotate,扭曲 skew,放缩 scale),我做了一些平常常用的一些简单的图标。 这些图标很多是通过三角形来拼贴起来的,所以我们需要知道怎么样画三角形。 1. 我们要将该 div 的 width 和 height 都设置为...