1. 程式人生 > >一段實現網站倒轉特效的javascript程式碼

一段實現網站倒轉特效的javascript程式碼

簡介

之前 一直有人惱火我的網站雙擊會變成黑白,然後文字顛倒,其實實現這個很簡單,把下面這段程式碼放到你的網站首頁即可

程式碼

<script>
(function () {
  var __timeout;
  var __lastTap = 0;
  var hell = function hell() {
    var hell = document.getElementById('hell');
    if (hell) {
      hell.parentNode.removeChild(hell);
    } else {
      var style = document.createElement('style');
      style.id = 'hell';
      style.textContent = 'body{ background:black; -webkit-transform: scale(-1,1); -ms-transform: scale(-1,1); transform: scale(-1,1); -webkit-filter: sepia(0) saturate(0) invert(1) brightness(1) c
ontrast(1); filter: sepia(0) saturate(0) invert(1) brightness(1) contrast(1); }';
      document.head.appendChild(style);
    }
  };
  document.addEventListener('dblclick', hell, false);
  document.addEventListener('touchend', function () {
    var currentTime = new Date().getTime();
    var tapLength = currentTime - __lastTap;
    clearTimeout(__timeout);
    if (tapLength < 500 && tapLength > 0) {
      hell();
    }
    __lastTap = currentTime;
  });
})();
</script>

歡迎關注Bboysoul的部落格www.bboysoul.co