通用的代码总结
Posted liangru
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通用的代码总结相关的知识,希望对你有一定的参考价值。
通用的代码总结
//在电脑浏览变成手机端,自适应手机端网站
var w = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
if (768>w){
window.location.href="http://m.1jianmedia.com" + window.location.href.replace(window.location.origin, "");
}
//利用JS来判断页面是在手机端还是在PC端打开的方法
window.location.href = /android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? "https://www.baidu.com/" : "http://news.baidu.com/";
//字符串为空返回true
isEmpty(obj) {
if (obj === null || obj === undefined || (typeof obj === "string" && obj.toLowerCase() === "null") || obj === "" || obj === 0 || obj.length === 0) {
return true;
} else {
return false;
}
},
判断浏览器还是微信分享
$("#shareId").click(function(){
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == ‘micromessenger‘){//微信浏览器
$(".sharemodel").show();
}else{
$(".model").show();
}
});
判断是安卓手机还是ios
changeIphone(){
var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf(‘Android‘) > -1 || u.indexOf(‘Linux‘) > -1; //g
if (isAndroid) {
return true
}else{
return false
}
},
//“全选”的全选事件
allChecked(){
let self = this;
if(this.$(".del_box input:checkbox").length === this.$(".del_box input:checked").length) {
this.$(‘.del_box input‘).each(function(i,v){
self.$(v).prop("checked", false);
});
this.$(‘.changebox input‘).prop("checked", false);
} else {
this.$(‘.del_box input‘).each(function(i,v){
self.$(v).prop("checked", true);
});
this.$(‘.changebox input‘).prop("checked", true);
}
},
S
// this.$nextTick(()=>{
// //设置默认选中项
// this.$(document).on(‘click‘,‘.accountTypeli‘,(e)=>{
// this.$(e.currentTarget).toggleClass(‘clicks‘);
// // if(this.$(e.currentTarget)[0].className.indexOf(‘clicks‘) == -1){
// // this.$(e.currentTarget).addClass("clicks");
// // }else{
// // this.$(e.currentTarget).removeClass("clicks");
// // }
// })
// })
//滚动条
<div class="public-number">
<ul class="public">
<li class="click">
<img class="definition" src="../../image/accountmsg/wechat.png" >
<p>微信公众号</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/mzl.png" >
<p>新浪微博</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/toutiao.png" >
<p>今日头条</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/baijia.png" >
<p>百家号</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/qie.png" >
<p>企鹅媒体平台</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/tout.png" >
<p>东方头条</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/fish.png" >
<p>大鱼号</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/onenumber.png" >
<p>一点资讯</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/sfox.png" >
<p>搜狐新闻</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/wangyi.png" >
<p>网易新闻</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/xinlang.png" >
<p>新浪看点</p>
</li>
<li class="click">
<img class="definition" src="../../image/accountmsg/bjtime.png" >
<p>北京时间</p>
</li>
<li class="click">
<img class="definition" src="../../image/accountmsg/fengh.png" >
<p>凤凰号</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/wechat.png" >
<p>微信公众号</p>
</li>
<li class="click">
<img class="definition" src="../../image/accountmsg/mzl.png" >
<p>新浪微博</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/toutiao.png" >
<p>今日头条</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/baijia.png" >
<p>百家号</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/qie.png" >
<p>企鹅媒体平台</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/tout.png" >
<p>东方头条</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/fish.png" >
<p>大鱼号</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/onenumber.png" >
<p>一点资讯</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/sfox.png" >
<p>搜狐新闻</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/wangyi.png" >
<p>网易新闻</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/xinlang.png" >
<p>新浪看点</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/bjtime.png" >
<p>北京时间</p>
</li>
<li>
<img class="definition" src="../../image/accountmsg/fengh.png" >
<p>凤凰号</p>
</li>
</ul>
</div>
.public-number{
background-color: #F2F2F2;
padding: .13rem .16rem .08rem;
box-sizing: border-box;
.public{
height: 1.72rem;
overflow-y:scroll;
display: flex;
flex-wrap: wrap;
&::-webkit-scrollbar{
width: 4px;
background-color: #FFFFFF;
border-radius: 2px;
}
&::-webkit-scrollbar-thumb{
background-color: #969696;
border-radius: 2px;
}
&::-ms-scrollbar{
width: 4px;
background-color: #FFFFFF;
border-radius: 2px;
}
&::-webkit-scrollbar-thumb{
background-color: #969696;
border-radius: 2px;
}
&::-o-scrollbar{
width: 4px;
background-color: #FFFFFF;
border-radius: 2px;
}
&::-o-scrollbar-thumb{
background-color: #969696;
border-radius: 2px;
}
&::-moz-scrollbar{
width: 4px;
background-color: #FFFFFF;
border-radius: 2px;
}
&::-moz-scrollbar-thumb{
background-color: #969696;
border-radius: 2px;
}
li{
width: 74px;
height: auto;
text-align: center;
position: relative;
margin-top: .12rem;
padding: 3px 1px;
border: 1px solid #F2F2F2;
cursor: pointer;
.definition{
width:.46rem;
height: .46rem;
}
p{
font-size: .12rem;
color: #7A7F82;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
.show{
width: .2rem;
height: .2rem;
position: absolute;
right: 8px;
top: -5px;
z-index: 999;
display: none;
}
&:hover{
.show{
display: block;
}
}
}
.click{
background: #fff;
border: 1px solid #CFCFCF;
border-radius: 3px;
}
}
}
以上是关于通用的代码总结的主要内容,如果未能解决你的问题,请参考以下文章