18910140161

用于总结前端常见场景的CSS/JS/插件(在更新实用文章的过程中.).

顺晟科技

2021-09-24 13:19:22

87

<div class="box box1">
        <span>垂直居中</span>
</div>
.box1{
    display: table-cell;
    vertical-align: middle;
    text-align: center;        
}
.box2{
    display: flex;
    justify-content:center;
    align-items:Center;
}

a链接 禁止点击跳转

javascript:void(0);


图片自适应

object-fit: cover;


vue 横向滚动条

父级:

overflow-y: hidden;
overflow-x: auto;
white-space: nowrap;
横向滚动条
.organ-result-content{
    width: 70%;
    height: 50px;
    overflow-y: hidden;
    overflow-x: auto;
    white-space: nowrap;
    font-size: 12px;
    position: fixed;
    bottom: 50px;
}
.organ-result-content-item{
    width: 65px;
    height: 28px;
    margin-top: 10px;
    margin-left: 5px;
    text-align: center;
    line-height: 28px;
    display: inline-block;
    border: 1px dashed #999;
    color: #666;
    position: relative;
}

鼠标指针放在一个元素边界范围内时所用的光标形状

cursor: pointer;


禁止选择
 -o-user-select: none;
  -moz-user-select: none; 
  -webkit-user-select: none; 
  -ms-user-select: none; 
  -khtml-user-select :none; 
  user-select: none;

设置边框不包含在长宽度里面:
box-sizing: border-box;


顶部固定效果
.tabbar{
	position:stycky;
	top:0;
	z-index:999
}
CSS实现单行、多行文本溢出显示省略号(…)
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
calc( - 20px)计算
position:absolute;position:relative定位使用通常是父级定义position:relative定位,子级定义position:absolute定位属性,并且子级使用left或right和top或bottom进行定位。

jQuery动态设置样式(style、css)

<div style="background-color:#ffffff;padding-left:10px;">测试jQuery动态获取padding-left</div>

1、用css()方法返回元素的样式属性

$("div").css("padding-left"));

2、用css()设置样式

$("div").css("color","yellow");

3、设置多个样式

$("div").css({"background-color":"yellow","font-size":"200%"});

var css = {  
    background-color: '#EEE',  
    height: '500px',  
    margin: '10px',  
    padding: '2px 5px'  
};  
$("div").css(css);

解决IE浏览器vue项目显示空白问题:

npm install --save @babel/polyfill


轮播图插件:

轮播图插件


阴影制作生成链接


测试浏览器是否可用

https://caniuse.com/


解决ie浏览器中formData.get()不生效问题
npm install formdata-polyfill
// 解决  ie浏览器图片上传  失败问题
import "formdata-polyfill";

数字字母自动换行不生效问题:
word-break: break-all;

// 登录ie内核浏览器  禁止访问该系统推荐使用Google(谷歌浏览器)
          var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
          if (userAgent.indexOf('Trident') !== -1 || userAgent.indexOf('MSIE') !== -1) { //表示使用的是IE的内核
            alert("该系统暂时不支持IE内核浏览器,推荐使用Google(谷歌浏览器)")
          } else{
            this.onNavgate()
          }

解决IE浏览器报forEach相关错误

nodelist-foreach-polyfill


解决后台带html格式在前台显示问题

white-space: pre-line;


实现前端浏览器下载文件
location.href = `${urlConfig.xsgl_serverUrl}${urlConfig.getExportAllHtqdAll}?xsglHtId=${this.params.dqJdId}`

使用Git下载指定分支命令为:

git clone -b 分支名仓库地址


VUE等数组的深拷贝和浅拷贝
data: {
  tabs:[]
}
let tabs = this.data.tabs;   //浅拷贝
let tabs = JSON.parse(JSON.stringify(this.data.tabs)); //深拷贝

url拼接:
http://172.18.19.22:19076/flexoffice/web/dist/modules/login/sso_login.html?loginName="+userName+"&token="+data

可以将json字符串转换成json对象

JSON.parse(jsonstr);

将json对象转换成json对符串

JSON.stringify(jsonobj); 
图片在固定容器内自适应
父级:position:relative;
img{
	max-height:340px;
	max-width:690px;
	position:absolute;
	left:0;
	right:0;
	top:0;
	bottom:0;
	margin:auto;
}

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航