#### 此方法封裝了鼠標向上/向下滾動時觸發的函數,只需傳入對應函數名
* * * * *
~~~
function scrollFunc(fnUp,fnDown){
//Firefox
if(document.addEventListener) {
document.addEventListener('DOMMouseScroll', scroll, false);
}
//IE及其他瀏覽器
window.onmousewheel = document.onmousewheel = scroll;
function scroll(e) {
e = e || window.event;
//IE/Opera/Chrome
if(e.wheelDelta) {
if(parseInt(e.wheelDelta) > 0) {
//鼠標向上滾動
if(fnUp){
fnUp();
}
} else {
//鼠標向下滾動
if(fnDown){
fnDown();
}
}
} else if(e.detail) { //Firefox
if(parseInt(e.detail) > 0) {
//鼠標向上滾動
if(fnUp){
fnUp();
}
} else {
//鼠標向下滾動
if(fnDown){
fnDown();
}
}
}
}
}
//示例
scrollFunc(up,down);
//向上滾動時觸發的函數
function up(){
if(document.documentElement.scrollTop > 200){
console.log('向上滾動距離頭部200px時觸發函數');
}
}
//向下滾動時觸發的函數
function down(){
if(document.documentElement.scrollTop > 300){
console.log('向下滾動距離頭部300px時觸發函數');
}
}
~~~
#### 鼠標滾動函數\~\~L表示滾動距頭部的距離,fn表示要執行的函數
* * * * *
~~~
function scrollFunc(L,fn) {
//Firefox
if(document.addEventListener) {
document.addEventListener('DOMMouseScroll', scrollFun, false);
}
//IE及其他瀏覽器
window.onmousewheel = document.onmousewheel = scrollFun;
function scrollFun(){
if(document.documentElement.scrollTop > L) {
fn();
}
}
}
//示例
scrollFunc(200,abc);
function abc(){
console.log('滾動距離頭部一定距離時觸發函數');
}
~~~
- 我的爛筆頭
- 1、常用功能方法整合
- 2、jQuery基本函數
- 3、在頁面中添加圖片
- 4、精度算法
- 5、圖片懶加載
- 6、彈窗拖拽功能
- 7、彈幕功能
- 8、鼠標滾動事件
- 9、獲取頁面相關屬性
- 10、彈窗的三種展現方式
- 11、輪播功能
- 12、獲取唯一標識
- 13、CSS樣式效果
- 14、任意兩點的動態連線
- 15、全新接口功能
- 16、適配兼容
- 17、無刷新頁面更改URL
- 18、定時器的那些事
- 19、關于iframe的常見問題
- 20、設置不同的時間
- 21、關于select-option
- 22、省市級聯
- 23、省市級聯數據
- 24、關于數據傳輸問題
- 25、問題分支
- 那些年我們一起走過的神坑
- 1、關于console的使用
- 2、關于數組
- 1、數組的賦值
- 2、數組的常用方法
- 3、關于移動端的bug
- 4、關于視頻的bug
- 5、那些坑坑洼洼
- 6、關于字符串
- 1、字符串的常用方法
- 頁面布局
- 1、背景固定的滾動頁面
- 心得
- Node.js
- 1、安裝環境
- ThinkPHP 5.1
- 1、訪問格式