当前位置: 首页 > news >正文

网站免费认证推广平台的方式有哪些

网站免费认证,推广平台的方式有哪些,哈尔滨站建站时间,做旅游网站的原因文章目录 概述引入与使用流程媒体查询条件语法规则媒体类型(media-type)媒体逻辑操作(media-logic-operations)媒体特征(media-feature) 场景示例1、监听设备屏幕的方向(竖屏,横屏&a…

文章目录

      • 概述
      • 引入与使用流程
      • 媒体查询条件
        • 语法规则
        • 媒体类型(media-type)
        • 媒体逻辑操作(media-logic-operations)
        • 媒体特征(media-feature)
      • 场景示例
        • 1、监听设备屏幕的方向(竖屏,横屏)
        • 2、监听设备尺寸变化(xs,sm,md,lg)

概述

媒体查询作为响应式设计的核心,在移动设备上应用十分广泛。媒体查询可根据不同设备类型或同设备不同状态修改应用的样式。

媒体查询常用于下面两种场景:

  • 针对设备和应用的属性信息(比如显示区域、深浅色、分辨率),设计出相匹配的布局。
  • 当屏幕发生动态改变时(比如分屏、横竖屏切换),同步更新应用的页面布局。

在这里插入图片描述

引入与使用流程

媒体查询通过mediaquery模块接口,设置查询条件并绑定回调函数,在对应的条件的回调函数里更改页面布局或者实现业务逻辑,实现页面的响应式设计。具体步骤如下:

  • 首先导入媒体查询模块。
import mediaquery from '@ohos.mediaquery';
  • 通过matchMediaSync接口设置媒体查询条件,保存返回的条件监听句柄listener。例如监听横屏事件:
let listener = mediaquery.matchMediaSync('(orientation: landscape)');
  • 给条件监听句柄listener绑定回调函数onPortrait,当listener检测设备状态变化时执行回调函数。
    在回调函数内,根据不同设备状态更改页面布局或者实现业务逻辑。
onPortrait(mediaQueryResult) {if (mediaQueryResult.matches) {// do something here} else {// do something here}
}listener.on('change', onPortrait);

媒体查询条件

媒体查询条件由媒体类型、逻辑操作符、媒体特征组成,其中媒体类型可省略,逻辑操作符用于连接不同媒体类型与媒体特征,其中,媒体特征要使用“()”包裹且可以有多个。具体规则如下:

语法规则

语法规则包括媒体类型(media-type)、媒体逻辑操作(media-logic-operations)和媒体特征(media-feature)。

[media-type] [media-logic-operations] [(media-feature)]

例如:

  • screen and (round-screen: true) :表示当设备屏幕是圆形时条件成立。

  • (max-height: 800) :表示当高度小于等于800vp时条件成立。

  • (height <= 800) :表示当高度小于等于800vp时条件成立。

  • screen and (device-type: tv) or (resolution < 2):表示包含多个媒体特征的多条件复杂语句查询,当设备类型为tv或设备分辨率小于2时条件成立。

媒体类型(media-type)
类型说明
screen按屏幕相关参数进行媒体查询。
媒体逻辑操作(media-logic-operations)

媒体逻辑操作符:and、or、not、only用于构成复杂媒体查询,也可以通过comma(, )将其组合起来,详细解释说明如下表。

表1 媒体逻辑操作符

类型说明
and将多个媒体特征(Media Feature)以“与”的方式连接成一个媒体查询,只有当所有媒体特征都为true,查询条件成立。另外,它还可以将媒体类型和媒体功能结合起来。例如:screen and (device-type: wearable) and (max-height: 600) 表示当设备类型是智能穿戴且应用的最大高度小于等于600个像素单位时成立。
or将多个媒体特征以“或”的方式连接成一个媒体查询,如果存在结果为true的媒体特征,则查询条件成立。例如:screen and (max-height: 1000) or (round-screen: true) 表示当应用高度小于等于1000个像素单位或者设备屏幕是圆形时,条件成立。
not取反媒体查询结果,媒体查询结果不成立时返回true,否则返回false。例如:not screen and (min-height: 50) and (max-height: 600) 表示当应用高度小于50个像素单位或者大于600个像素单位时成立。
使用not运算符时必须指定媒体类型。
only当整个表达式都匹配时,才会应用选择的样式,可以应用在防止某些较早的版本的浏览器上产生歧义的场景。一些较早版本的浏览器对于同时包含了媒体类型和媒体特征的语句会产生歧义,比如:screen and (min-height: 50)。老版本浏览器会将这句话理解成screen,从而导致仅仅匹配到媒体类型(screen),就应用了指定样式,使用only可以很好地规避这种情况。
使用only时必须指定媒体类型。
comma(, )将多个媒体特征以“或”的方式连接成一个媒体查询,如果存在结果为true的媒体特征,则查询条件成立。其效果等同于or运算符。例如:screen and (min-height: 1000), (round-screen: true) 表示当应用高度大于等于1000个像素单位或者设备屏幕是圆形时,条件成立。

媒体范围操作符包括<=,>=,<,>,详细解释说明如下表。

表2 媒体逻辑范围操作符

类型说明
<=小于等于,例如:screen and (height <= 50)。
>=大于等于,例如:screen and (height >= 600)。
<小于,例如:screen and (height < 50)。
>大于,例如:screen and (height > 600)。
媒体特征(media-feature)

媒体特征包括应用显示区域的宽高、设备分辨率以及设备的宽高等属性,详细说明如下表。

表3 媒体特征说明表

类型说明
height应用页面可绘制区域的高度。
min-height应用页面可绘制区域的最小高度。
max-height应用页面可绘制区域的最大高度。
width应用页面可绘制区域的宽度。
min-width应用页面可绘制区域的最小宽度。
max-width应用页面可绘制区域的最大宽度。
resolution设备的分辨率,支持dpi,dppx和dpcm单位。其中:
- dpi表示每英寸中物理像素个数,1dpi ≈ 0.39dpcm;
- dpcm表示每厘米上的物理像素个数,1dpcm ≈ 2.54dpi;
- dppx表示每个px中的物理像素数(此单位按96px = 1英寸为基准,与页面中的px单位计算方式不同),1dppx = 96dpi。
min-resolution设备的最小分辨率。
max-resolution设备的最大分辨率。
orientation屏幕的方向。
可选值:
- orientation: portrait(设备竖屏);
- orientation: landscape(设备横屏)。
device-height设备的高度。
min-device-height设备的最小高度。
max-device-height设备的最大高度。
device-width设备的宽度。
device-type设备的类型。
可选值:default、tablet。
min-device-width设备的最小宽度。
max-device-width设备的最大宽度。
round-screen屏幕类型,圆形屏幕为true,非圆形屏幕为false。
dark-mode系统为深色模式时为true,否则为false。

场景示例

1、监听设备屏幕的方向(竖屏,横屏)
import mediaquery from '@ohos.mediaquery';@Entry
@Component
struct MediaQueryExample {@State color: string = '#DB7093';@State text: string = '设备竖屏';// 当设备横屏时条件成立listener = mediaquery.matchMediaSync('(orientation: landscape)');// 当满足媒体查询条件时,触发回调onPortrait(mediaQueryResult) {if (mediaQueryResult.matches) { // 若设备为横屏状态,更改相应的页面布局this.color = '#FFD700';this.text = '设备横屏';} else {this.color = '#DB7093';this.text = '设备竖屏';}}aboutToAppear() {// 绑定回调函数this.listener.on('change', this.onPortrait.bind(this));}build() {Column() {Text(this.text).fontSize(50).fontColor(this.color).margin({top:50})}.width('100%').height('100%')}
}

在这里插入图片描述

2、监听设备尺寸变化(xs,sm,md,lg)
  • 工具类BreakpointSystem
// utils/BreakpointSystem.etsimport mediaQuery from '@ohos.mediaquery';export class BreakpointSystem {private currentBreakpoint: string = 'sm';private xsListener: mediaQuery.MediaQueryListener;private smListener: mediaQuery.MediaQueryListener;private mdListener: mediaQuery.MediaQueryListener;private lgListener: mediaQuery.MediaQueryListener;public register(): void {this.xsListener = mediaQuery.matchMediaSync('(width<320vp)');this.xsListener.on('change', this.isBreakpointXS);this.smListener = mediaQuery.matchMediaSync('(320vp<=width<600vp)');this.smListener.on('change', this.isBreakpointSM);this.mdListener = mediaQuery.matchMediaSync('(600vp<=width<840vp)');this.mdListener.on('change', this.isBreakpointMD);this.lgListener = mediaQuery.matchMediaSync('(840vp<=width)');this.lgListener.on('change', this.isBreakpointLG);}public unregister(): void {this.xsListener.off('change', this.isBreakpointXS);this.smListener.off('change', this.isBreakpointSM);this.mdListener.off('change', this.isBreakpointMD);this.lgListener.off('change', this.isBreakpointLG);}private isBreakpointXS = (mediaQueryResult: mediaQuery.MediaQueryResult): void => {if (mediaQueryResult.matches) {this.updateCurrentBreakpoint('xs');}}private isBreakpointSM = (mediaQueryResult: mediaQuery.MediaQueryResult): void => {if (mediaQueryResult.matches) {this.updateCurrentBreakpoint('sm');}}private isBreakpointMD = (mediaQueryResult: mediaQuery.MediaQueryResult): void => {if (mediaQueryResult.matches) {this.updateCurrentBreakpoint('md');}}private isBreakpointLG = (mediaQueryResult: mediaQuery.MediaQueryResult): void => {if (mediaQueryResult.matches) {this.updateCurrentBreakpoint('lg');}}private updateCurrentBreakpoint(breakpoint: string): void {if (this.currentBreakpoint !== breakpoint) {this.currentBreakpoint = breakpoint;AppStorage.SetOrCreate<string>('currentBreakpoint', this.currentBreakpoint);}}
}
  • 使用工具类监听设备尺寸
// mediaQuery.etsimport { BreakpointSystem } from '../utils/BreakpointSystem'@Entry
@Component
struct MediaQueryExample {@StorageProp('currentBreakpoint') currentBreakpoint: string = 'sm'private breakpointSystem: BreakpointSystem = new BreakpointSystem();aboutToAppear() {// 注册监听this.breakpointSystem.register()}aboutToDisappear() {// 移除监听this.breakpointSystem.unregister()}build() {Column() {Text(this.currentBreakpoint).fontSize(50).margin({ top: 50 })}.width('100%').height('100%')}
}

在这里插入图片描述

http://www.dinnco.com/news/18065.html

相关文章:

  • 南开区网站建设某个产品营销推广方案
  • 网站开发+职位描述seozhun
  • 济南微信网站建设百度网址大全在哪里找
  • vs2010做网站登陆界面网站流量查询站长之家
  • 给做网站建设的一些建议免费发布推广的网站
  • 网站建设水上乐园新闻软文发稿平台
  • 网站设计实训报告网页设计工作室长沙
  • 免费域名网站seo文案范例
  • wordpress社会评论插件杭州seo网站优化
  • 阿里云 拦截网站腾讯云服务器
  • 云瓣科技做网站seo个人优化方案案例
  • 做网站去哪里备案谷歌官网登录入口
  • 用js做跳转到其他网站广东疫情最新资讯
  • 地产网站建设方案微信指数
  • 大场网站建设福州网站建设团队
  • 哪类型网站容易做郑州网络营销排名
  • 网络销售有限公司聊城seo培训
  • 建设公司内网网站的意义泰安百度推广电话
  • 网站建设必要步骤啥都能看的浏览器
  • 科汛 kesioncms v8.05 企业网站建设入门视频教程seo综合优化公司
  • synology做网站服务器下载百度app到桌面
  • 麻涌网站建设百度指数官方网站
  • 怎么开电商店铺无锡网站建设优化公司
  • 电商网站 建设步骤seo优化服务商
  • 如何用oss做视频网站网上的推广
  • php7安装wordpress北京网站优化策略
  • 云南 网站建设网站爱站网为什么不能用了
  • 互联网开网站怎么做老域名购买
  • 代购网站怎么做的百度开店怎么收费
  • 做的好的商城网站设计9个成功的市场营销案例