JavaScript

js获得页面高度

javascript获得页面的可视宽高和页面自身宽高,兼容浏览器.
function GetPageSize() {
    var scrW, scrH;
    if(window.innerHeight && window.scrollMaxY) {
        // Mozilla
        scrW = window.innerWidth + window.scrollMaxX;

javascript 判断页面是否在iframe下

当iframe不在父窗口打开时,跳转到父窗口

var parent_url = 'http://www.pecloud.cn';
if(parent.document.URL== document.URL) {
 window.location.href = parent_url;
} else {
 //...
}
if(window.top == window) {
 window.top.location = parent_url;
} else {
 //...
}

jquery 获得鼠标指针 X/Y 值

 $(document).ready(function() {

  $().mousemove(function(e) {

    // display the x and y axis values inside the div with the id XY

    $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);

  });

});

<div id="XY"></div>

jquery 得到html中元素的数量

 

$(document).ready(function() {

  $("p").size();

});

jquery 验证元素是否存在

 $(document).ready(function() {

  if ($('#id').length) {

    // do something

  }

});

jquery 元素居中间

 $(document).ready(function() {

  jQuery.fn.center = function() {

    this.css("position","absolute");

    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");

jquery page top

 $(document).ready(function() {

  $('a[href*=#]').click(function() {

   if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')

       && location.hostname == this.hostname) {

     var $target = $(this.hash);

jquery font resizing

 $(document).ready(function() {

  // Reset the font size(back to default)

  var originalFontSize = $('html').css('font-size');

  $(".resetFont").click(function() {

    $('html').css('font-size', originalFontSize);

  });

  // Increase the font size(bigger font0

jquery 保持div的列高度相同

 $(document).ready(function() {

  function equalHeight(group) {

    tallest = 0;

    group.each(function() {

      thisHeight = $(this).height();

      if (thisHeight > tallest) {

        tallest = thisHeight;

jquery 预加载图片

 $(document).ready(function() {

  jQuery.preloadImages = function() {

    for(var i = 0; i < arguments.length; i++) {

      $("<img>").attr("src", arguments[i]);

    }

  }

 

  // how to use

同步内容