智能小程序 Ray 开发实践——视图容器组件 View 介绍

View

用于页面布局的元素

导入

import { View } from '@ray-js/ray';

属性说明

属性类型默认值说明支持平台
styleCSSProperties样式涂鸦、微信
classNamestring样式名涂鸦、微信
hoverClassNamestringnonehover 样式涂鸦、微信
hoverStylestringnonehover 样式名涂鸦、微信
hoverStartTimenumber20按住后多久出现点击态 单位 ms涂鸦、微信
hoverStayTimenumber70手指松开后点击态保留时间 ms涂鸦、微信

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。 

 

示例代码

  • index.module.less
.view {
  background-color: #e67d1b;
  height: 120rpx;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}
.innerView {
  background-color: #e67d1b;
  height: 120rpx;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 10rpx;
}
 
.hoverView {
  background-color: #1f6de2;
}
 
.hoverTransition {
  background-color: #1f6de2;
  transition: background-color linear 0.3s;
}

flex 布局

import React from 'react';
 
import { View } from '@ray-js/components';
 
import styles from './index.module.less';
 
export default function flex() {
  const click = (e) => {
    console.log('click');
  };
  return (
    <View style={{ display: 'flex', flexDirection: 'row', width: '100%' }}>
      <View
        onTouchEnd={click}
        style={{ flex: 1 }}
        hoverClassName={styles.hoverView}
        className={styles.innerView}
      >
        A
      </View>
      <View
        style={{ flex: 1 }}
        hoverClassName={styles.hoverView}
        className={styles.innerView}
      >
        B
      </View>
      <View
        style={{ flex: 1 }}
        hoverClassName={styles.hoverView}
        className={styles.innerView}
      >
        C
      </View>
    </View>
  );
}

基本使用

import React from 'react';
 
import { View } from '@ray-js/components';
 
import styles from './index.module.less';
 
export default function () {
  let t = 0;
  return (
    <View
      hoverClassName={styles.hoverView}
      hoverStyle={{ backgroundColor: '#f00' }}
      className={styles.view}
      onTouchStart={() => {
        t = Date.now();
        console.log('touch start');
      }}
      onTouchEnd={() => {
        console.log('touch end');
      }}
      onClick={() => {
        console.log(`${Date.now() - t}ms`);
      }}
    >
      按住变色
    </View>
  );
}

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IoT砖家涂拉拉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值