前端填坑

前端知识点

2020-03-24  本文已影响0人  StAndres

HTML及其他基础知识部分


Js部分

const data = null;
console.log(typeof(data));
// Object
// 这里是一个Js的历史遗留问题,所以不能单纯的用typeof来验证

if(!Object.is(data, undefined) && Object.is(data, data)) {
  // data is null
}
var a = {name: a, value: 1}
b = a
b.name = “1”
console.log(a.name) // 1
function quickSort(arr){
  if(arr.length<1){
    return arr;
  }
  var pivotIndex=Math.floor(arr.length/2);//找到那个基准数
  var pivot=arr.splice(pivotIndex,1)[0]; //取出基准数,并去除,splice返回值为数组。
  var left=[]; 
  var right=[];
  for(var i=0;i<arr.length;i++){
    if(arr[i]<pivot){
      left.push(arr[i]);
    }else{
      right.push(arr[i]);
    }
  }
  return quickSort(left).concat([pivot],quickSort(right)); //加入基准数
}
// 时间戳方案
function throttle(fn,wait){
    var pre = Date.now();
    return function(){
        var context = this;
        var args = arguments;
        var now = Date.now();
        if( now - pre >= wait){
            fn.apply(context,args);
            pre = Date.now();
        }
    }
}

function handle(){
    console.log(Math.random());
}
    
window.addEventListener("mousemove",throttle(handle,1000));
// 定时器方案
function throttle(fn,wait){
    var timer = null;
    return function(){
        var context = this;
        var args = arguments;
        if(!timer){
            timer = setTimeout(function(){
                fn.apply(context,args);
                timer = null;
            },wait)
        }
    }
}
    
function handle(){
    console.log(Math.random());
}
    
window.addEventListener("mousemove",throttle(handle,1000));
[] == 0 // true
![] == 0 // true
[] == ![] // true
[] == [] // false
{} == !{} // false
{} == {} // false

Css部分

/* Css3水平居中 */
{display: flex; justify-content: center;}
/* Css3垂直居中 */
{display: flex; align-items: center;}
/* Css2水平居中 */
{display: inline; text-align: center;}
/* Css2垂直居中 */
{height: 200px; line-height: 200px}
<html>
    <body>
        <div id="container">
            <div id="attr"></div>
        </div>
    </body>
</html>

<style>
    #container {
        width: 80%;
        height: 500px;
    }

    #attr {
        width: 50%;
        height: 0;
        padding-bottom: 50%;
        background-color: aqua;
    }
</style>

Vue部分


其他

上一篇 下一篇

猜你喜欢

热点阅读