DIV CSS 佈局教程網

JavaScript 滑鼠特效七大實作範例
編輯:關於JavaScript     

JavaScript 滑鼠特效整理

本文整理常見滑鼠互動效果,包含右鍵停用、游標樣式、移入移出、自動捲動、連結色彩與滑輪停用。

1. 停用滑鼠右鍵

document.onmousedown = function(event){
  if(event.button == 2){
    alert('已停用滑鼠右鍵');
  }
};

event.button 可用來區分左鍵、右鍵與中鍵組合。

2. 動態游標

pDom.style.cursor = 'pointer';

cursor 可設定 default、pointer、move、help、text、progress、resize 等值。

3. 移入放大文字

function mOver(el){ el.style.fontSize = '20px'; }
function mOut(el){ el.style.fontSize = ''; }

4. 雙擊自動捲動

var timer;
document.ondblclick = function(){
  timer = setInterval(function(){ window.scrollBy(0, 1); }, 10);
};
document.onmousedown = function(){ clearInterval(timer); };

5. 連結移入變色

linkDOMs[i].onmouseover = function(){
  this.style.color = 'red';
};
linkDOMs[i].onmouseout = function(){
  this.style.color = '';
};

6. 停用滑鼠滑輪

document.onmousewheel = function(){
  alert('禁止使用滑輪');
  return false;
};

這些效果多用於增強互動,實際專案仍可搭配事件監聽與樣式類別,讓程式碼更易維護。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved