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

新乡模板建站优化提升

新乡模板建站,优化提升,小程序个人开发全过程,请专业公司做个网站要花多少钱今天菜鸟涨工资了,到手估计有8000左右了,有点开心,本来想上一篇就把这篇写了的,但是发现还是分开写比较好! 文章目录自适应js禁止放大播放声音store的使用websocket封装echarts实现渐变swiper常用的陌生方法&#xff0…

今天菜鸟涨工资了,到手估计有8000左右了,有点开心,本来想上一篇就把这篇写了的,但是发现还是分开写比较好!

文章目录

  • 自适应js
  • 禁止放大
  • 播放声音
  • store的使用
  • websocket封装
  • echarts实现渐变
  • swiper
  • 常用的陌生方法(只做记录,不介绍具体用法,持续更新)

自适应js

; (function (win) {var bodyStyle = document.createElement('style')bodyStyle.innerHTML = `body{width:1920px; height:1200px}`  // 需要适配的屏幕的宽高document.documentElement.firstElementChild.appendChild(bodyStyle)function refreshScale() {let docWidth = document.documentElement.clientWidthlet docHeight = document.documentElement.clientHeightvar designWidth = 1920 // 需要适配的屏幕的宽var designHeight = 1200  // 需要适配的屏幕的高var widthRatio = 0widthRatio = docWidth / designWidthvar heightRatio = 0heightRatio = docHeight / designHeightdocument.body.style ='transform:scale(' +widthRatio +',' +heightRatio +');transform-origin:left top;'// 应对浏览器全屏切换前后窗口因短暂滚动条问题出现未占满情况setTimeout(function () {var lateWidth = document.documentElement.clientWidth,lateHeight = document.documentElement.clientHeightif (lateWidth === docWidth) returnwidthRatio = lateWidth / designWidthheightRatio = lateHeight / designHeightdocument.body.style ='transform:scale(' +widthRatio +',' +heightRatio +');transform-origin:left top;'}, 0)}refreshScale()window.addEventListener('pageshow',function (e) {if (e.persisted) {// 浏览器后退的时候重新计算refreshScale()}},false)window.addEventListener('resize', refreshScale, false)
})(window);

这个自适应是最简单的自适应,主要用来对一些等比例的屏幕或者长宽比相近的屏幕的适配,主要还是针对类似电脑屏幕的适配!

注意:
1、如果项目有3d相关的操作,那么这个可能会适得其反,让本来百分比就可以适配的变得不适配!参考:swiper 3d 结合 loop 向左移动缺少一个内容

2、手机端、pad端还是建议使用px2rem,参考我的:使用px2rem不生效

禁止放大

// 禁用双指放大
document.documentElement.addEventListener('touchstart',function (event) {if (event.touches.length > 1) {event.preventDefault()}},{passive: false,}
);// 禁用双击放大
var lastTouchEnd = 0
document.documentElement.addEventListener('touchend',function (event) {var now = Date.now()if (now - lastTouchEnd <= 300) {event.preventDefault()}lastTouchEnd = now},{passive: false}
)

播放声音

// 添加音频
const audiodom = document.createElement("audio");
audiodom.setAttribute("id", "callmusic");
audiodom.setAttribute("loop", "loop");
audiodom.setAttribute("src", "static/audio/game_start.mp3");
document.body.appendChild(audiodom);
const callmusic = document.getElementById("callmusic");
callmusic.play();// 移除音频
const callmusic = document.getElementById("callmusic");
document.body.removeChild(callmusic);

注意:
1、如果一个界面有好几个音频,一定要取不同的名字!
2、如果是组件里面有音频,而组件会复用,那么一定要动态绑定id!
eg:

audiodom.setAttribute("id", "callmusic"+this.id)  // id由父组件传入

store的使用

store在项目中真的很容易使用到,但是每个界面都用什么this.$sotre.xxx的真的很麻烦,所以一定要记得这几个方法:

import {mapState, mapMutations, mapGetters} from "vuex";

每一个的使用:

在这里插入图片描述
在这里插入图片描述

websocket封装

websocket确实使用起来很简单,但是最好搞一个统一的断线重连以及连接流程,不然真的不太好规范!

这里菜鸟把公司一个同事的封装的献上:

data:

// 连接地址
websocketUrlPlay: xxxxxx,
// 断线重连
lockReconnect: false,
// 重连定时器
reconnetTimer: null

method:

// 重连
reconnect() {if (this.lockReconnect) {return;}this.lockReconnect = true;// 没连接上会一直重连,设置延迟避免请求过多this.reconnetTimer && clearTimeout(this.reconnetTimer);this.reconnetTimer = setTimeout(() => {this.createWebsocketPlay();this.lockReconnect = false;}, 4000);
},// 创建websocket
createWebsocketPlay() {// eslint-disable-next-linethis.socket = new WebSocket(this.websocketUrlPlay);this.socket.onopen = () => {// onopen 连接触发console.log("websocket pad open");};this.socket.onclose = () => {// onclose 断开触发console.log("websocket close");this.reconnect();};this.socket.onerror = () => {console.log("发生异常了");this.reconnect();};this.socket.onmessage = (event) => {// console.log(JSON.parse(event.data));const data = JSON.parse(event.data);}
}

注意:

1、这个 lockReconnect 类似于java中的 锁,所以 断开连接的时候一定要置为true

this.lockReconnect = true;
clearTimeout(this.reconnetTimer);
this.reconnetTimer = null;setTimeout(()=>{this.socket.close();
},100);  // 建议关闭时延时,可以更加有效!

echarts实现渐变

itemStyle: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: "#17e5a2" },{ offset: 1, color: "#23e8ca" },]),
},

swiper

1、swiper数据变化后,重新渲染

this.$nextTick(()=>{this.mySwiper.update();
})

常用的陌生方法(只做记录,不介绍具体用法,持续更新)

1、findIndex
2、some
3、

http://www.khdw.cn/news/495.html

相关文章:

  • 网站建设的目入图片企业宣传推广
  • 长沙做网站的推广计划书范文
  • 哈尔滨行业网站电商营销
  • 网站底部备案号代码珠海seo快速排名
  • java做网站教程长春网站建设推广
  • 全自动网站制作系统青岛官网seo方法
  • 手机网站打开微信支付功能广州白云区新闻头条最新消息今天
  • 初识网站开发流程图网络公关
  • 网站办公室文化建设自己怎么制作网页
  • 网站界面设计如何实现功能美与形式美的统一网络营销推广方案3篇
  • 在那些免费网站做宣传效果好河南seo快速排名
  • 网站制作视频教程新手必看宁波seo网络推广产品服务
  • 成都网站制作公司科蓝上海谷歌seo公司
  • 跨境网络营销案例安卓优化大师官网下载
  • asp.net做的网站要放到网上空间去_要放哪些文件上去windows系统优化软件
  • 中装建设集团网站网盟推广是什么意思
  • 网站开发需要的知识搜索推广是什么意思
  • 宁波制作网站公司口碑seo推广公司
  • 工商网站查询个人信息临沂seo排名外包
  • wordpress大学 主题廊坊seo排名收费
  • 天津做美缝的网站搜索引擎优化seo论文
  • 西安网站手机网站建设搜索引擎优化的方法包括
  • 免费推广网站建设整合营销经典案例
  • 北京做网站要多少钱免费代码网站
  • 鹿泉网站制作公司常州seo
  • wordpress 调取栏目广州seo外包
  • 网站建设的增值税税率网站seo优化总结
  • iis 默认网站 删除企业的网络推广
  • 找兼职工作在家做正规网站账号权重查询
  • 天峻县公司网站建设seo的优化策略有哪些