分类 front-end 下的文章

来自 http://www.zzhck.com/535.html

代码

<script type="text/javascript" language="javascript">
(function() {
function k(a, b, c) {
if (a.addEventListener) a.addEventListener(b, c, false);
else a.attachEvent && a.attachEvent("on" + b, c)
}
function g(a) {
if (typeof window.onload != "function") window.onload = a;
else {
var b = window.onload;
window.onload = function() {
b();
a()
}
}
}
function h() {
var a = {};
for (type in {
Top: "",
Left: ""
}) {
var b = type == "Top" ? "Y": "X";
if (typeof window["page" + b + "Offset"] != "undefined")
a[type.toLowerCase()] = window["page" + b + "Offset"];
else {
b = document.documentElement.clientHeight ? document.documentElement: document.body;
a[type.toLowerCase()] = b["scroll" + type]
}
}
return a
}
function l() {
var a = document.body,
b;
if (window.innerHeight) b = window.innerHeight;
else if (a.parentElement.clientHeight) b = a.parentElement.clientHeight;
else if (a && a.clientHeight) b = a.clientHeight;
return b
}
function i(a) {
this.parent = document.body;
this.createEl(this.parent, a);
this.size = Math.random() * 5 + 5;
this.el.style.width = Math.round(this.size) + "px";
this.el.style.height = Math.round(this.size) + "px";
this.maxLeft = document.body.offsetWidth - this.size;
this.maxTop = document.body.offsetHeight - this.size;
this.left = Math.random() * this.maxLeft;
this.top = h().top + 1;
this.angle = 1.4 + 0.2 * Math.random();
this.minAngle = 1.4;
this.maxAngle = 1.6;
this.angleDelta = 0.01 * Math.random();
this.speed = 2 + Math.random()
}
var j = false;
g(function() {
j = true
});
var f = true;
window.createSnow = function(a, b) {
if (j) {
var c = [],
m = setInterval(function() {
f && b > c.length && Math.random()
< b * 0.0025 && c.push(new i(a)); ! f && !c.length && clearInterval(m);
for (var e = h().top, n = l(), d = c.length - 1; d >= 0; d--)
if (c[d]) if (c[d].top < e || c[d].top + c[d].size + 1 > e + n) {
c[d].remove();
c[d] = null;
c.splice(d, 1)
} else {
c[d].move();
c[d].draw()
}
},
40);
k(window, "scroll",
function() {
for (var e = c.length - 1; e >= 0; e--) c[e].draw()
})
} else g(function() {
createSnow(a, b)
})
};
window.removeSnow = function() {
f = false
};
i.prototype = {
createEl: function(a, b) {
this.el = document.createElement("img");
this.el.setAttribute
("src", b + "雪花图片的绝对链接地址");
this.el.style.position = "absolute";
this.el.style.display = "block";
this.el.style.zIndex = "99999";
this.parent.appendChild(this.el)
},
move: function() {
if (this.angle < this.minAngle || this.angle > this.maxAngle)
this.angleDelta = -this.angleDelta;
this.angle += this.angleDelta;
this.left += this.speed * Math.cos(this.angle * Math.PI);
this.top -= this.speed * Math.sin(this.angle * Math.PI);
if (this.left < 0) this.left = this.maxLeft;
else if (this.left > this.maxLeft) this.left = 0
},
draw: function() {
this.el.style.top = Math.round(this.top) + "px";
this.el.style.left = Math.round(this.left) + "px"
},
remove: function() {
this.parent.removeChild(this.el);
this.parent = this.el = null
}
}
})();
createSnow("", 40);
</script>
将以上面代码直接复制粘贴到主题中的Header或者Footer文件中,
如果你只想让文章页面显示,那就直接添加到single就可以了。

雪花图片大家可以自己百度搜索,
本站所用的图片是:http://dl.m69w.com/wordpress/snow.png

来自 http://www.xhily.cn/archives/76.html
有木有发现网站一打开上方有一个红色的加载条

一会又没有了 是不是很炫酷啊

今天就教大家怎么弄

其实也是一个大神教的了 可是他的博客关了 就不介绍了

在此 感谢 断青丝大神

代码:

HTML

<script src="2.js"></script>
<link href="2.css" rel="stylesheet" />

Js

(function() {
  var AjaxMonitor, Bar, DocumentMonitor, ElementMonitor, ElementTracker, EventLagMonitor, Evented, Events, NoTargetError, RequestIntercept, SOURCE_KEYS, Scaler, SocketRequestTracker, XHRRequestTracker, animation, avgAmplitude, bar, cancelAnimation, cancelAnimationFrame, defaultOptions, extend, extendNative, getFromDOM, getIntercept, handlePushState, ignoreStack, init, now, options, requestAnimationFrame, result, runAnimation, scalers, shouldTrack, source, sources, uniScaler, _WebSocket, _XDomainRequest, _XMLHttpRequest, _i, _intercept, _len, _pushState, _ref, _ref1, _replaceState,
    __slice = [].slice,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  defaultOptions = {
    catchupTime: 500,
    initialRate: .03,
    minTime: 500,
    ghostTime: 500,
    maxProgressPerFrame: 10,
    easeFactor: 1.25,
    startOnPageLoad: true,
    restartOnPushState: true,
    restartOnRequestAfter: 500,
    target: 'body',
    elements: {
      checkInterval: 100,
      selectors: ['body']
    },
    eventLag: {
      minSamples: 10,
      sampleCount: 3,
      lagThreshold: 3
    },
    ajax: {
      trackMethods: ['GET'],
      trackWebSockets: false
    }
  };

  now = function() {
    var _ref;
    return (_ref = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void  : void 0) != null ? _ref : +(new Date);
  };

  requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

  cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;

  if (requestAnimationFrame == null) {
    requestAnimationFrame = function(fn) {
      return setTimeout(fn, 50);
    };
    cancelAnimationFrame = function(id) {
      return clearTimeout(id);
    };
  }

  runAnimation = function(fn) {
    var last, tick;
    last = now();
    tick = function() {
      var diff;
      diff = now() - last;
      if (diff >= 33) {
        last = now();
        return fn(diff, function() {
          return requestAnimationFrame(tick);
        });
      } else {
        return setTimeout(tick, 33 - diff);
      }
    };
    return tick();
  };

  result = function() {
    var args, key, obj;
    obj = arguments[

  extend = function() {
    var key, out, source, sources, val, _i, _len;
    out = arguments[], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
    for (_i = 0, _len = sources.length; _i < _len; _i++) {
      source = sources[_i];
      if (source) {
        for (key in source) {
          if (!__hasProp.call(source, key)) continue;
          val = source[key];
          if ((out[key] != null) && typeof out[key] === 'object' && (val != null) && typeof val === 'object') {
            extend(out[key], val);
          } else {
            out[key] = val;
          }
        }
      }
    }
    return out;
  };

  avgAmplitude = function(arr) {
    var count, sum, v, _i, _len;
    sum = count = 0;
    for (_i = 0, _len = arr.length; _i < _len; _i++) {
      v = arr[_i];
      sum += Math.abs(v);
      count++;
    }
    return sum / count;
  };


  getFromDOM = function(key, json) {
    var data, e, el;
    if (key == null) {
      key = 'options';
    }
    if (json == null) {
      json = true;
    }
    el = document.querySelector("[data-pace-" + key + "]");
    if (!el) {
      return;
    }
    data = el.getAttribute("data-pace-" + key);
    if (!json) {
      return data;
    }
    try {
      return JSON.parse(data);
    } catch (_error) {
      e = _error;
      return typeof console !== "undefined" && console !== null ? console.error("Error parsing inline pace options", e) : void 0;
    }
  };

  Evented = (function() {
    function Evented() {}

    Evented.prototype.on = function(event, handler, ctx, once) {
      var _base;
      if (once == null) {
        once = false;
      }

      if (this.bindings == null) {
        this.bindings = {};
      }
      if ((_base = this.bindings)[event] == null) {
        _base[event] = [];
      }
      return this.bindings[event].push({
        handler: handler,
        ctx: ctx,
        once: once
      });
    };

    Evented.prototype.once = function(event, handler, ctx) {
      return this.on(event, handler, ctx, true);
    };

    Evented.prototype.off = function(event, handler) {
      var i, _ref, _results;
      if (((_ref = this.bindings) != null ? _ref[event] : void 0) == null) {
        return;
      }
      if (handler == null) {
        return delete this.bindings[event];
      } else {
        i = 0;
        _results = [];
        while (i < this.bindings[event].length) {
          if (this.bindings[event][i].handler === handler) {
            _results.push(this.bindings[event].splice(i, 1));
          } else {
            _results.push(i++);
          }
        }
        return _results;
      }
    };

    Evented.prototype.trigger = function() {
      var args, ctx, event, handler, i, once, _ref, _ref1, _results;
      event = arguments[], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
      if ((_ref = this.bindings) != null ? _ref[event] : void 0) {
        i = 0;
        _results = [];
        while (i < this.bindings[event].length) {
          _ref1 = this.bindings[event][i], handler = _ref1.handler, ctx = _ref1.ctx, once = _ref1.once;
          handler.apply(ctx != null ? ctx : this, args);
          if (once) {
            _results.push(this.bindings[event].splice(i, 1));
          } else {
            _results.push(i++);
          }
        }
        return _results;
      }
    };


    return Evented;

  })();

  if (window.Pace == null) {
    window.Pace = {};
  }

  extend(Pace, Evented.prototype);

  options = Pace.options = extend({}, defaultOptions, window.paceOptions, getFromDOM());

  _ref = ['ajax', 'document', 'eventLag', 'elements'];
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    source = _ref[_i];
    if (options[source] === true) {
      options[source] = defaultOptions[source];
    }
  }

  NoTargetError = (function(_super) {
    __extends(NoTargetError, _super);

    function NoTargetError() {
      _ref1 = NoTargetError.super.constructor.apply(this, arguments);
      return _ref1;
    }

    return NoTargetError;

  })(Error);

  Bar = (function() {
    function Bar() {
      this.progress = 0;
    }

    Bar.prototype.getElement = function() {
      var targetElement;
      if (this.el == null) {
        targetElement = document.querySelector(options.target);
        if (!targetElement) {
          throw new NoTargetError;
        }
        this.el = document.createElement('div');
        this.el.className = "pace pace-active";
        document.body.className = document.body.className.replace('pace-done', '');
        document.body.className += ' pace-running';
        this.el.innerHTML = '<div class="pace-progress">\n  <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>';
        if (targetElement.firstChild != null) {
          targetElement.insertBefore(this.el, targetElement.firstChild);
        } else {
          targetElement.appendChild(this.el);
        }
      }
      return this.el;
    };

    Bar.prototype.finish = function() {
      var el;
      el = this.getElement();
      el.className = el.className.replace('pace-active', '');
      el.className += ' pace-inactive';
      document.body.className = document.body.className.replace('pace-running', '');
      return document.body.className += ' pace-done';
    };

    Bar.prototype.update = function(prog) {
      this.progress = prog;
      return this.render();
    };

    Bar.prototype.destroy = function() {
      try {
        this.getElement().parentNode.removeChild(this.getElement());
      } catch (_error) {
        NoTargetError = _error;
      }
      return this.el = void 0;
    };

    Bar.prototype.render = function() {
      var el, progressStr;
      if (document.querySelector(options.target) == null) {
        return false;
      }
      el = this.getElement();
      el.children[

    Bar.prototype.done = function() {
      return this.progress >= 100;
    };

    return Bar;

  })();

  Events = (function() {
    function Events() {
      this.bindings = {};
    }

    Events.prototype.trigger = function(name, val) {
      var binding, _j, _len1, _ref2, _results;
      if (this.bindings[name] != null) {
        _ref2 = this.bindings[name];
        _results = [];
        for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
          binding = _ref2[_j];
          _results.push(binding.call(this, val));
        }
        return _results;
      }
    };

    Events.prototype.on = function(name, fn) {
      var _base;
      if ((_base = this.bindings)[name] == null) {
        _base[name] = [];
      }
      return this.bindings[name].push(fn);
    };

    return Events;

  })();

  _XMLHttpRequest = window.XMLHttpRequest;

  _XDomainRequest = window.XDomainRequest;

  _WebSocket = window.WebSocket;

  extendNative = function(to, from) {
    var e, key, val, _results;
    _results = [];
    for (key in from.prototype) {
      try {
        val = from.prototype[key];
        if ((to[key] == null) && typeof val !== 'function') {
          _results.push(to[key] = val);
        } else {
          _results.push(void 0);
        }
      } catch (_error) {

        e = _error;

      }

    }

    return _results;

  };


  ignoreStack = [];


  Pace.ignore = function() {

    var args, fn, ret;

    fn = arguments[


  Pace.track = function() {

    var args, fn, ret;

    fn = arguments[


  shouldTrack = function(method) {

    var _ref2;

    if (method == null) {

      method = 'GET';

    }

    if (ignoreStack[] === 'track') {

      return 'force';

    }

    if (!ignoreStack.length && options.ajax) {

      if (method === 'socket' && options.ajax.trackWebSockets) {

        return true;

      } else if (_ref2 = method.toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref2) >= 0) {

        return true;

      }

    }

    return false;

  };


  RequestIntercept = (function(_super) {

    __extends(RequestIntercept, _super);


    function RequestIntercept() {

      var monitorXHR,

        _this = this;

      RequestIntercept.super.constructor.apply(this, arguments);

      monitorXHR = function(req) {

        var _open;

        _open = req.open;

        return req.open = function(type, url, async) {

          if (shouldTrack(type)) {

            _this.trigger('request', {

              type: type,

              url: url,

              request: req

            });

          }

          return _open.apply(req, arguments);

        };

      };

      window.XMLHttpRequest = function(flags) {

        var req;

        req = new _XMLHttpRequest(flags);

        monitorXHR(req);

        return req;

      };

      extendNative(window.XMLHttpRequest, _XMLHttpRequest);

      if (_XDomainRequest != null) {

        window.XDomainRequest = function() {

          var req;

          req = new _XDomainRequest;

          monitorXHR(req);

          return req;

        };

        extendNative(window.XDomainRequest, _XDomainRequest);

      }

      if ((_WebSocket != null) && options.ajax.trackWebSockets) {

        window.WebSocket = function(url, protocols) {

          var req;

          req = new _WebSocket(url, protocols);

          if (shouldTrack('socket')) {

            _this.trigger('request', {

              type: 'socket',

              url: url,

              protocols: protocols,

              request: req

            });

          }

          return req;

        };

        extendNative(window.WebSocket, _WebSocket);

      }

    }


    return RequestIntercept;


  })(Events);


  _intercept = null;


  getIntercept = function() {

    if (_intercept == null) {

      _intercept = new RequestIntercept;

    }

    return _intercept;

  };


  getIntercept().on('request', function(_arg) {

    var after, args, request, type;

    type = _arg.type, request = _arg.request;

    if (!Pace.running && (options.restartOnRequestAfter !== false || shouldTrack(type) === 'force')) {

      args = arguments;

      after = options.restartOnRequestAfter || 0;

      if (typeof after === 'boolean') {

        after = 0;

      }

      return setTimeout(function() {

        var stillActive, _j, _len1, _ref2, _ref3, _results;

        if (type === 'socket') {

          stillActive = request.readyState < 2;

        } else {

          stillActive = (0 < (_ref2 = request.readyState) && _ref2 < 4);

        }

        if (stillActive) {

          Pace.restart();

          _ref3 = Pace.sources;

          _results = [];

          for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {

            source = _ref3[_j];

            if (source instanceof AjaxMonitor) {

              source.watch.apply(source, args);

              break;

            } else {

              _results.push(void 0);

            }

          }

          return _results;

        }

      }, after);

    }

  });


  AjaxMonitor = (function() {

    function AjaxMonitor() {

      var _this = this;

      this.elements = [];

      getIntercept().on('request', function() {

        return _this.watch.apply(_this, arguments);

      });

    }


    AjaxMonitor.prototype.watch = function(_arg) {

      var request, tracker, type;

      type = _arg.type, request = _arg.request;

      if (type === 'socket') {

        tracker = new SocketRequestTracker(request);

      } else {

        tracker = new XHRRequestTracker(request);

      }

      return this.elements.push(tracker);

    };


    return AjaxMonitor;


  })();


  XHRRequestTracker = (function() {

    function XHRRequestTracker(request) {

      var event, size, _j, _len1, _onreadystatechange, _ref2,

        _this = this;

      this.progress = 0;

      if (window.ProgressEvent != null) {

        size = null;

        request.addEventListener('progress', function(evt) {

          if (evt.lengthComputable) {

            return _this.progress = 100 * evt.loaded / evt.total;

          } else {

            return _this.progress = _this.progress + (100 - _this.progress) / 2;

          }

        });

        _ref2 = ['load', 'abort', 'timeout', 'error'];

        for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {

          event = _ref2[_j];

          request.addEventListener(event, function() {

            return _this.progress = 100;

          });

        }

      } else {

        _onreadystatechange = request.onreadystatechange;

        request.onreadystatechange = function() {

          var _ref3;

          if ((_ref3 = request.readyState) ===  || _ref3 === 4) {

            _this.progress = 100;

          } else if (request.readyState === 3) {

            _this.progress = 50;

          }

          return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;

        };

      }

    }


    return XHRRequestTracker;


  })();


  SocketRequestTracker = (function() {

    function SocketRequestTracker(request) {

      var event, _j, _len1, _ref2,

        _this = this;

      this.progress = 0;

      _ref2 = ['error', 'open'];

      for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {

        event = _ref2[_j];

        request.addEventListener(event, function() {

          return _this.progress = 100;

        });

      }

    }


    return SocketRequestTracker;


  })();


  ElementMonitor = (function() {

    function ElementMonitor(options) {

      var selector, _j, _len1, _ref2;

      if (options == null) {

        options = {};

      }

      this.elements = [];

      if (options.selectors == null) {

        options.selectors = [];

      }

      _ref2 = options.selectors;

      for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {

        selector = _ref2[_j];

        this.elements.push(new ElementTracker(selector));

      }

    }


    return ElementMonitor;


  })();


  ElementTracker = (function() {

    function ElementTracker(selector) {

      this.selector = selector;

      this.progress = 0;

      this.check();

    }


    ElementTracker.prototype.check = function() {

      var _this = this;

      if (document.querySelector(this.selector)) {

        return this.done();

      } else {

        return setTimeout((function() {

          return _this.check();

        }), options.elements.checkInterval);

      }

    };


    ElementTracker.prototype.done = function() {

      return this.progress = 100;

    };


    return ElementTracker;


  })();


  DocumentMonitor = (function() {

    DocumentMonitor.prototype.states = {

      loading: 0,

      interactive: 50,

      complete: 100

    };


    function DocumentMonitor() {

      var _onreadystatechange, _ref2,

        _this = this;

      this.progress = (_ref2 = this.states[document.readyState]) != null ? _ref2 : 100;

      _onreadystatechange = document.onreadystatechange;

      document.onreadystatechange = function() {

        if (_this.states[document.readyState] != null) {

          _this.progress = _this.states[document.readyState];

        }

        return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;

      };

    }


    return DocumentMonitor;


  })();


  EventLagMonitor = (function() {

    function EventLagMonitor() {

      var avg, interval, last, points, samples,

        _this = this;

      this.progress = 0;

      avg = 0;

      samples = [];

      points = 0;

      last = now();

      interval = setInterval(function() {

        var diff;

        diff = now() - last - 50;

        last = now();

        samples.push(diff);

        if (samples.length > options.eventLag.sampleCount) {

          samples.shift();

        }

        avg = avgAmplitude(samples);

        if (++points >= options.eventLag.minSamples && avg < options.eventLag.lagThreshold) {

          _this.progress = 100;

          return clearInterval(interval);

        } else {

          return _this.progress = 100 * (3 / (avg + 3));

        }

      }, 50);

    }


    return EventLagMonitor;


  })();


  Scaler = (function() {

    function Scaler(source) {

      this.source = source;

      this.last = this.sinceLastUpdate = 0;

      this.rate = options.initialRate;

      this.catchup = 0;

      this.progress = this.lastProgress = 0;

      if (this.source != null) {

        this.progress = result(this.source, 'progress');

      }

    }


    Scaler.prototype.tick = function(frameTime, val) {

      var scaling;

      if (val == null) {

        val = result(this.source, 'progress');

      }

      if (val >= 100) {

        this.done = true;

      }

      if (val === this.last) {

        this.sinceLastUpdate += frameTime;

      } else {

        if (this.sinceLastUpdate) {

          this.rate = (val - this.last) / this.sinceLastUpdate;

        }

        this.catchup = (val - this.progress) / options.catchupTime;

        this.sinceLastUpdate = 0;

        this.last = val;

      }

      if (val > this.progress) {

        this.progress += this.catchup  frameTime;

      }

      scaling = 1 - Math.pow(this.progress / 100, options.easeFactor);

      this.progress += scaling  this.rate * frameTime;

      this.progress = Math.min(this.lastProgress + options.maxProgressPerFrame, this.progress);

      this.progress = Math.max(0, this.progress);

      this.progress = Math.min(100, this.progress);

      this.lastProgress = this.progress;

      return this.progress;

    };


    return Scaler;


  })();


  sources = null;


  scalers = null;


  bar = null;


  uniScaler = null;


  animation = null;


  cancelAnimation = null;


  Pace.running = false;


  handlePushState = function() {

    if (options.restartOnPushState) {

      return Pace.restart();

    }

  };


  if (window.history.pushState != null) {

    _pushState = window.history.pushState;

    window.history.pushState = function() {

      handlePushState();

      return _pushState.apply(window.history, arguments);

    };

  }


  if (window.history.replaceState != null) {

    _replaceState = window.history.replaceState;

    window.history.replaceState = function() {

      handlePushState();

      return _replaceState.apply(window.history, arguments);

    };

  }


  SOURCE_KEYS = {

    ajax: AjaxMonitor,

    elements: ElementMonitor,

    document: DocumentMonitor,

    eventLag: EventLagMonitor

  };


  (init = function() {

    var type, _j, _k, _len1, _len2, _ref2, _ref3, _ref4;

    Pace.sources = sources = [];

    _ref2 = ['ajax', 'elements', 'document', 'eventLag'];

    for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {

      type = _ref2[_j];

      if (options[type] !== false) {

        sources.push(new SOURCE_KEYStype);

      }

    }

    _ref4 = (_ref3 = options.extraSources) != null ? _ref3 : [];

    for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {

      source = _ref4[_k];

      sources.push(new source(options));

    }

    Pace.bar = bar = new Bar;

    scalers = [];

    return uniScaler = new Scaler;

  })();


  Pace.stop = function() {

    Pace.trigger('stop');
    Pace.running = false;
    bar.destroy();
    cancelAnimation = true;
    if (animation != null) {
      if (typeof cancelAnimationFrame === "function") {
        cancelAnimationFrame(animation);
      }
      animation = null;
    }
    return init();
  };

  Pace.restart = function() {
    Pace.trigger('restart');
    Pace.stop();
    return Pace.start();
  };

  Pace.go = function() {
    Pace.running = true;
    bar.render();
    cancelAnimation = false;
    return animation = runAnimation(function(frameTime, enqueueNextFrame) {
      var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, start, sum, _j, _k, _len1, _len2, _ref2;
      remaining = 100 - bar.progress;
      count = sum = 0;
      done = true;
      for (i = _j = 0, _len1 = sources.length; _j < _len1; i = ++_j) {
        source = sources[i];
        scalerList = scalers[i] != null ? scalers[i] : scalers[i] = [];
        elements = (_ref2 = source.elements) != null ? _ref2 : [source];
        for (j = _k = 0, _len2 = elements.length; _k < _len2; j = ++_k) {
          element = elements[j];
          scaler = scalerList[j] != null ? scalerList[j] : scalerList[j] = new Scaler(element);
          done &= scaler.done;
          if (scaler.done) {
            continue;
          }
          count++;
          sum += scaler.tick(frameTime);
        }
      }
      avg = sum / count;
      bar.update(uniScaler.tick(frameTime, avg));
      start = now();
      if (bar.done() || done || cancelAnimation) {
        bar.update(100);
        Pace.trigger('done');
        return setTimeout(function() {
          bar.finish();
          Pace.running = false;
          return Pace.trigger('hide');
        }, Math.max(options.ghostTime, Math.min(options.minTime, now() - start)));
      } else {
        return enqueueNextFrame();
      }
    });
  };

  Pace.start = function(_options) {
    extend(options, _options);
    Pace.running = true;
    try {
      bar.render();
    } catch (_error) {
      NoTargetError = _error;
    }
    if (!document.querySelector('.pace')) {
      return setTimeout(Pace.start, 50);
    } else {
      Pace.trigger('start');
      return Pace.go();
    }
  };

  if (typeof define === 'function' && define.amd) {
    define(function() {
      return Pace;
    });
  } else if (typeof exports === 'object') {
    module.exports = Pace;
  } else {
    if (options.startOnPageLoad) {
      Pace.start();
    }
  }
}).call(this);

CSS

.pace {

-webkit-pointer-events:none;

pointer-events:none;

-webkit-user-select:none;

-moz-user-select:none;

user-select:none;

}

.pace-inactive {

display:none;

}

.pace .pace-progress {

background:#d9534f;/ 颜色控制 /

position:fixed;

z-index:2000;/ 长度控制 /

top:0;

left:0;

height:3px;/ 宽度控制 /

-webkit-transition:width 0.1s; / 时间控制 /

-moz-transition:width 0.1s;  / 时间控制 /

-o-transition:width 0.1s; / 时间控制 /

transition:width 0.1s; / 时间控制 /

}

代码托管在 Runjs 上点击提取

这里打包好了的

来自老赵茶馆的:http://zhw-island.com/wordpress/jquery-qrcode.html

A collection of web development logos in SVG :link

Svg的好处就不多说了,实际上wordpress默认是不支持svg上传的,在functions.php文件里添加以下代码即可

/* SVG支持 */
function my_upload_mimes($mimes = array()) {
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'my_upload_mimes');

来自老赵茶馆的使用jQuery.qrcode为WordPress文章动态生成二维码

jQuery.qrcode地址:link
在线生成器:link

网上流传的方法是采用外网的API方式生成,好处是简单粗暴,缺点是自定义不够;我主题使用的是jQuery.qrcode,好处是自定义功能丰富,缺点是要加载额外js。
首先是载入jQuery,载入jQuery.qrcode,然后在single.php里加入以下代码:

<script>
jQuery(window).load(function() {
    jQuery("#qrcode").qrcode({
        text: "<?php the_permalink(); ?>"
    });
});
</script>

当然,这是最简单的配置,再加些css美化下就OK了,下面说说所有配置的,可按需添加。

{
    // 渲染方式默认有html5的画布canvas,还有image、div
    render: 'canvas',
 
    // 版本version范围为1到40,就是格子的密度
    minVersion: 1,
    maxVersion: 40,
 
    // 容错率从低到高四种模式: 'L', 'M', 'Q' or 'H'
    ecLevel: 'L',
 
    // 如果画布渲染时的上像素偏移
    left: 0,
    top: 0,
 
    // 像素大小
    size: 200,
 
    // 填充颜色
    fill: '#000',
 
    // 背景颜色
    background: null,
 
    // 内容,可以使文本或者网址
    text: 'no text',
 
    // 圆角: 0.0 到 0.5
    radius: 0,
 
    // 空白的边界
    quiet: 0,
 
    //模式
    // 0: normal,正常模式即最简洁模式
    // 1: label strip,可插入标签条
    // 2: label box,可插入标签盒子
    // 3: image strip,可插入图像条
    // 4: image box,可插入图像盒子
    mode: 0,
 
    // 分别是标签或图像的缩放,x偏移,y偏移
    mSize: 0.1,
    mPosX: 0.5,
    mPosY: 0.5,
 
    // 标签文字、字体、颜色
    label: 'no label',
    fontname: 'sans',
    fontcolor: '#000',
 
    // 图像的地址
    image: null
}

就这么简单,就是有一个难点,就是模式3和模式4的插入图像问题,你不能直接在image选项后面直接填入图像地址,那样会报错。作者解释说道,在运行生成二维码之前,图像必须先载入,然后通过选择器填入image选项。
就是说,图像必须在二维码之前载入,那就简单,我把图像载入但是通过css把它隐藏掉

<div id="qrcode">
     <img id="qrcode_img" style="display:none" src="/images/qr-img.png">
</div>
 
 
...
 
<script>
jQuery(window).load(function() {
    jQuery("#qrcode").qrcode({
        mode: 4,
    image: jQuery('#qrcode_img')[0],
        text: "<?php the_permalink(); ?>"
    });
});
</script>
 
...




















var allLi=document.getElementById("slideUl_a");
var classCss=" ;background:#FEFAF1;border:1px solid #FED79E;";
var classCss2=" ;background:#fff;border:1px solid #fff;";
var allLiQuery=allLi.getElementsByTagName("li");
var lilen=allLiQuery.length;
for(var i =0;i<lilen;i++){
    allLiQuery[i].onmouseover=function(){
         this.style.cssText+=classCss; 
    }
    allLiQuery[i].onmouseout=function(){
         this.style.cssText+=classCss2; 
    }
}

from http://www.laifuying.com/archives/554

Highlight.js是一个开源的JS框架,用于网页代码高亮。当它运行时,会自动读取pre标签的文本并自动识别语言。当然,也可以通过给class赋值做到手动设置语言。
使用方法很简单。


一些链接

官方github地址
官方网站
主题&效果预览
下载地址


获取

可以直接下载JS文件并自行编译使用,或者任选以下两个CDN之一使用

jsdelivr

在header标签中加入

<link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/8.8.0/styles/default.min.css"> 

在网页footer处加入

<script src="//cdn.jsdelivr.net/highlight.js/8.8.0/highlight.min.js"></script>

或者是cdnjs

在网页header处加入

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/styles/default.min.css">

在网页footer处加入

<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/highlight.min.js"></script>

我推荐使用Jsdelivr。从ping服务器测试可以看到,Jsdelivr在中国境内几乎每个省份都有CDN节点,延迟最低可以达到10ms-。而CloudFlare的cdnjs就显得不那么尽人意。

使用


开启功能

只要在底部加入函数

<script>hljs.initHighlightingOnLoad();</script>

即可

网页标签用法

<pre><code class="php">
    <?php echo 'hello world'; ?>
</code></pre>

以此类推
如果不想让pre中的代码高亮,给class加上nohighlight样式即可

<pre><code class="nohighlight">...</code></pre>


修改主题的方法

highlight.js提供了大量的主题,可以在 主题&效果预览 中挑选。
例如我选择了"vs"主题,只要将引用的css修改为

<link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/8.8.0/styles/vs.min.css">

就可以了

在博客程序中的用法


Pagekit

site->设置->Code
将代码对应加入header和footer

Wordpress

主题->编辑
手动编辑header.php和footer.php

Typecho

与WordPress同理,直接修改header和footer即可

转自:https://touko.moe/blog/howtouse-highlightjs

HTML

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Tab切换</title>
    <link type="text/css" rel="stylesheet" href="style.css">
    <script src="app.js"></script>
</head>
<body>
    <div class="tab"  id="tab">
        <div class="tab-title" id = "tab-title">
            <ul>
                <li class="select">
                    <a href="#">公告</a>
                </li>
                <li>
                    <a href="#">规则</a>
                </li>
                <li>
                    <a href="#">论坛</a>
                </li>
                <li>
                    <a href="#">安全</a>
                </li>
                <li>
                    <a href="#">公益</a>
                </li>
            </ul>
        </div>
        <div class="tab-content" id="tab-content">
            <div class="tabct" style="display: block">
                <ul>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">故宫创意产品来袭啦</a>
                    </li>
                    <li>
                        <a href="#">阿里发布 YunOS 3.0</a>
                    </li>
                    <li>
                        <a href="#">阿里云运营智慧城市</a>
                    </li>
                </ul>
            </div>
            <div class="tabct"  style="display: none">
                <ul>
                    <li>
                        <a href="#">谨防假冒客服诱导退款</a>
                    </li>
                    <li>
                        <a href="#">国企业厂家大联动</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                </ul>
            </div>
            <div class="tabct" style="display: none">
                <ul>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">国企业厂家大联动</a>
                    </li>
                </ul>
            </div>
            <div class="tabct" style="display: none">
                <ul>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">国企业厂家大联动</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                </ul>
            </div>
            <div class="tabct" style="display: none">
                <ul>
                    <li>
                        <a href="#">国企业厂家大联动</a>
                    </li>
                    <li>
                        <a href="#">国企业厂家大联动</a>
                    </li>
                    <li>
                        <a href="#">八千家4S店参与双11</a>
                    </li>
                    <li>
                        <a href="#">国企业厂家大联动</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</body>
</html>

CSS

*{
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 12px;
}

.tab{
    width: 298px;
    height: 98px;
    margin: 10px;
    border: 1px solid #eee;
    overflow: hidden;
}

.tab-title{
    height: 27px;
    position: relative;
    background: #f7f7f7;
}

.tab-title ul{
    position: absolute;
    width: 301px;
    left: -1;
}
.tab-title li{
    float: left;
    width: 58px;
    height: 26px;
    line-height: 26px;
    text-align: center;
    padding: 0 1px;
    border-bottom: 1px solid #eee;
    overflow: hidden;
}

.tab li a:link,.tab li a:visited{
    text-decoration: none;
    color: #000;
}
.tab li a:hover{
    color:#f90;
    font-weight: 700;
}

.tab-title li.select{
    background: #fff;
    border-bottom-color: #fff;
    border-left: 1px solid #eee;
    border-right: 1px solid #eee;
    padding: 0;
}

.tab .tab-content .tabct{
    margin: 10px 10px 10px 19px;
}

.tab .tab-content .tabct ul li{
    float: left;
    width: 134px;
    height: 25px;
    overflow: hidden;
}

JS

function $(id){
    return typeof  id=="string"?document.getElementById(id):id;
}

window.onload = function(){
    var titleName = $("tab-title").getElementsByTagName("li");
    var tabContent = $("tab-content").getElementsByTagName("div");
    if(titleName.length != tabContent.length){
        return;
    }
    for(var i = 0;i<titleName.length;i++){
        titleName[i].id = i;
        titleName[i].onmouseover = function(){
            for(var j = 0;j<titleName.length;j++){
                titleName[j].className = "";
                tabContent[j].style.display = "none"
            }
            this.className = "select";
            tabContent[this.id].style.display = "block";
        }
    }
}

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>添加两个方法到jQuery原型($.fn)</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
    label {
        display: block;
        margin: .5em;
    }
</style>
</head>
<body>
 
<label><input type="checkbox" name="foo"> Foo</label>
<label><input type="checkbox" name="bar"> Bar</label>
<script>
$(function () { 
    $.fn.extend({
        check: function() {
            return this.each(function() {
                this.checked = true;
            });
        },
        uncheck: function() {
            return this.each(function() {
                this.checked = false;
            });
        }
    });
    // 使用新创建的.check() 方法
    $( "input[type='checkbox']" ).check();
})
</script>
 
</body>
</html>

使用 function 参数处理来自 AJAX 请求的数据结果。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>使用 function 参数处理来自 AJAX 请求的数据结果</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("div").load("demo_cd_catalog.xml",function(response,status){
            if (status=="success"){
                $("div").html("<ol></ol>");
                $(response).find("artist").each(function(){
                    var item_text = $(this).text();
                    $('<li></li>').html(item_text).appendTo('ol');
                });
                //alert("总共有 "+$(response).find("cd").size()+" 张 CD")
            }else{
                $("div").html("错误信息: <br/>" + xhr.status + " " + xhr.statusText)
            }
        });
    });
});
</script>
</head>
<body>

<p>艺术家</p>
<div></div>
<button>获取 CD 信息</button>
<p> XML 文件实例为 <a href="demo_cd_catalog.xml" target="_blank">demo_cd_catalog</a></p>

</body>
</html>

demo_cd_catalog.xml

post.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQ-post</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.post("/post.php",{
            name:"jqpost",
            url:"http://www.baidu.com"
        },
        function(data,status){
            alert("数据: \n" + data + "\n状态: " + status);
        });
    });
});
</script>
</head>
<body>

<button>发送一个 HTTP POST 请求页面并获取返回内容</button>

</body>
</html>

post.php

<?php
$name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '';
$city = isset($_POST['url']) ? htmlspecialchars($_POST['url']) : '';
echo '网站名: ' . $name;
echo "\n";
echo 'URL 地址: ' .$city;
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>获取 JSON 数据</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.getJSON("demo_ajax_json.js",function(result){
            $.each(result,function(i,field){
                $("div").append(field+"<br>");
            })
        })
    })
})

</script>
</head>
<body>

<button>获取 JSON 数据</button>
<div></div>

</body>
</html>

demo_ajax_json.js

{ 
  "firstName": "Bill",
  "lastName": "Gates",
  "age": 60
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>按钮动画</title>
    <link rel="stylesheet" href="">
    <style>
    .button{
        display: inline-block;
        border-radius: 4px;
        background-color: #f4511e;
        border: none;
        color: white;
        text-align: center;
        font-size: 28px;
        padding: 20px;
        width: 200px;
        transition: all 0.5s;
        cursor: pointer;
        margin: 5px;
    }
    .button span{
        cursor: pointer;
        display: inline-block;
        position: relative;
        transition: 0.5s;
    }
    .button span:after{
        content: '»';
        display: inline-block;
        opacity: 0;
        top: 0;
        right: -20px;
        transition: 0.5s;
    }
    .button:hover span{
        padding-right: 25px;
    }
    .button:hover span:after{
        opacity: 1;
        right: 0;
    }
    </style>
</head>
<body>
    <button class="button"><span>Hover </span></button>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>CSS3-面包屑导航</title> 
<style>
ul.breadcrumb {
    padding: 8px 16px;
    list-style: none;
    background-color: #eee;
}
ul.breadcrumb li {display: inline;}
ul.breadcrumb li+li:before {
    padding: 8px;
    color: black;
    content: "/\00a0";
}
ul.breadcrumb li a {color: green;}
</style>
</head>
<body>

<h2>面包屑导航</h2>
<ul class="breadcrumb">
  <li><a href="#">首页 </a></li>
  <li><a href="#">前端 </a></li>
  <li><a href="#">HTML 教程 </a></li>
  <li>HTML 段落</li>
</ul>

</body>
</html>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>CSS3-图片模态框</title> 
<style>
#myImg {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {    
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform: scale(0)} 
    to {-webkit-transform: scale(1)}
}

@keyframes zoom {
    from {transform: scale(0.1)} 
    to {transform: scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}
</style>
</head>
<body>

<h2>图片模态框</h2>
<p>本实例演示了如何结合 CSS 和 JavaScript 来一起渲染图片。</p><p>
首先,我们使用 CSS 来创建 modal 窗口 (对话框), 默认是隐藏的。<p>
<p>然后,我们使用 JavaScript 来显示模态窗口,当我们点击图片时,图片会在弹出的窗口中显示:</p>
<img id="myImg" src="http://www.runoob.com/wp-content/uploads/2016/04/img_lights.jpg" alt="Northern Lights, Norway" width="300" height="200">

<!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">×</span>
  <img class="modal-content" id="img01">
  <div id="caption"></div>
</div>

<script>
// 获取模态窗口
var modal = document.getElementById('myModal');

// 获取图片模态框,alt 属性作为图片弹出中文本描述
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    modalImg.alt = this.alt;
    captionText.innerHTML = this.alt;
}

// 获取 <span> 元素,设置关闭模态框按钮
var span = document.getElementsByClassName("close")[0];

// 点击 <span> 元素上的 (x), 关闭模态框
span.onclick = function() { 
    modal.style.display = "none";
}
</script>

</body>
</html>