當控制瀏覽器滾動到邊界時javascript
overscroll-behavior:containcss
.dialog{
position: fixed;
z-index: 5;
width:200px;
height:200px;
border:1px solid;
left:50%;
top:50%;
transform: translate(-50%,-50%);
background-color: #eee;
overflow: auto;
font-size:14px;
color:#222;
overscroll-behavior-y: none;
/*或者
overscroll-behavior-y:contain;
*/
}
複製代碼
auto : 默認值 滾動到邊緣後繼續滾動外部的可滾動容器。java
contain : 阻止滾動鏈。es6
none : 和 contain 同樣,但它也能夠防止節點自己的滾動效果(例如 Android 炫光或 iOS 回彈)編程
contain和none的行爲差別體現主要在移動端後端
overscroll-behavior-x: none瀏覽器
能夠禁止左右滑動的手勢導航bash
IE 瀏覽器寫法: -ms-scroll-chainingwordpress
developer.mozilla.org/zh-CN/docs/…
www.zhangxinxu.com/wordpress/2…
網頁容器滾動中止的時候,自動平滑定位到你但願用戶關注的重點區域
容器scroll-snap-type,子元素scroll-snap-align
做用在滾動父容器上 | 做用在滾動子元素上 |
---|---|
scroll-snap-type | scroll-snap-align |
scroll-snap-stop | scroll-margin/scroll-margin-(top/right/bottom/left)(用於精肯定位) |
scroll-padding/scroll-padding-(top/right/bottom/left) (用於精肯定位) |
應用範圍:滾動父容器上 說明:肯定是水平滾動定位,仍是垂直滾動定位
第一個參數:指定哪一個軸
第二個參數:指定形式
應用範圍:滾動父容器上【還在實驗階段】 說明:是否容許滾動容器忽略捕獲位置
應用範圍:滾動子元素上 說明:捕獲點是上邊緣,下邊緣,仍是中間位置
www.cnblogs.com/lonelyxmas/…
www.zhangxinxu.com/wordpress/2…
選擇沒有任何子級的元素(包括文本節點)
針對後端返回的字段中有空值的狀況,能夠不用判斷是否爲空顯示「暫無數據」
selector:empty
PS:有空格,不算爲空
好比渲染連接
selector:empty
之前的作法:
<a href="http://www.baidu.com">http://www.baidu.com</a>
複製代碼
能夠用:empty
<a href="http://www.baidu.com" title="百度"></a>
a[href^="http"]:empty::before {
content: attr(href);
}
複製代碼
將數字的小數部分去掉,只保留整數部分
以前:
Math.floor(10.2) //10
Math.ceil(-10.2) // -10
如今:
Math.trunc(10.2) //10
Math.trunc(-10.2) //-10
複製代碼
parseInt('100.2kg') // 100
Math.trunc('100.2kg') //NaN
複製代碼
對於trunc ,若是參數爲字符串的話,內部會先使用Number將其先轉爲數值
Math.trunc(true) //1
Math.trunc(false) // 0
Math.trunc(null) // 0
複製代碼
developer.mozilla.org/zh-CN/docs/…
表面意思:粘性的,粘性定位能夠被認爲是相對定位(relative)和固定定位(fixed)的混合。 元素在跨越特定閾值前爲相對定位,以後爲固定定位
假設咱們設置:
nav{
position:sticky;
top:20px;
}
複製代碼
頁面向下滾動時,nav的父元素div ,一旦視口的頂部與nav的距離小於20px(閾值),nav 就自動變爲fixed定位。 頁面繼續向下滾動,父元素div完全離開視口(即整個父元素div徹底不可見),nav恢復成relative定位。
ps: 1,sticky生效的前提是,必須搭配top、bottom、left、right這四個屬性一塊兒使用 2,父級元素不能有任何overflow:visible之外的overflow設置,不然沒有粘滯效果。由於改變了滾動容器
developer.mozilla.org/zh-CN/docs/…
www.zhangxinxu.com/wordpress/2…
www.ruanyifeng.com/blog/2019/1…
1,查看animation 動畫過程,能夠有效查看動畫的細節,方便調試
2,訪問的圖片能夠直接獲取base64,不用再找工具進行圖片轉換base64了
javascript中只有對象,沒有類的概念,是基於原型的面嚮對象語言
class寫法只是讓對象原型的寫法更加清晰、更像面向對象編程的語法而已。
function Person(name,age) {
this.name = name;
this.age=age;
}
Person.prototype.say = function(){
return "個人名字叫" + this.name+"今年"+this.age+"歲了";
}
var obj=new Person("zhangsan",18);
複製代碼
class Person{
constructor(name,age){//constructor是一個構造方法,用來接收參數
this.name = name;//this表明的是實例對象
this.age=age;
}
say(){
return "個人名字叫" + this.name+"今年"+this.age+"歲了";
}
}
var obj=new Person("zhangsan",18);
注:不存在變量提高
//ES5能夠先使用再定義,存在變量提高
new Person();
function Person(){}
//ES6不存在變量提高,不然會報錯
new Person();//Person is not defined
class Person {}
複製代碼
class Person {
constructor() {}
static say(words) {
alert(words)
}
}
靜態方法不在實例化對象的方法中,
所以裏面不能有this,
使用方法:Person.say()
該方法不會被實例繼承, 是直接經過類來調用
複製代碼
class Person {}
Person.say = function() {}
複製代碼
super 既能夠看成函數使用,也能夠看成對象使用
class Parent {
constructor(name) {
this.name = name;
}
}
class Child extends Parent {
constructor(name) {
//this.name = name; // ReferenceError
super(name);//子類的構造函數必須執行一次 super 函數,不然會報錯。
}
}
//var parent = new Parent();
var child = new Child('金');
document.write(child.name)
注:
子類必須在constructor方法中調用super方法,而後再對其進行加工
只有調用super以後,纔可使用this關鍵字,不然會報錯
複製代碼
class Parent {
constructor(name) {
this.name = name;
}
say(){
document.write('我姓'+this.name+',我能夠說話了');
}
}
class Child extends Parent {
constructor(name) {
super(name);
}
test(){
super.say()
}
}
var child = new Child('金');
child.test();
複製代碼