zoukankan      html  css  js  c++  java
  • 非常好的javascript 代码

     与其他Javascript类库冲突解决方案
    
    $(document).ready(function()
     {
    
    var $jq = jQuery.noConflict();
    
    $jq('#id').show();
    
    });
    使元素居屏幕中间位置
    
    $(document).ready(function() 
    {
    
    jQuery.fn.center = function () 
    {
         this.css("position","absolute");
         this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    
     this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    
     return this;
    
     }
    
     $("#id").center();
    
     });
    使整个DIV可点击
    
     $(document).ready(function()
     {
    
    $("div").click(function()
    {
    
    window.location=$(this).find("a").attr("href"); return false;
    
     });
    
     // how to use
    
     <DIV><A href="index.html">home</A></DIV>
    
    
    
    });
    jQuery延时加载功能view plaincopy to clipboardprint?
    
    $(document).ready(function() 
    {
    window.setTimeout(function() 
    {
    
    
    
     }, 1000);
    
     });
    获得鼠标指针XY值
    
     $(document).ready(function()
     {
    
     $().mousemove(function(e)
    {
    
     $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
    
     });
    
     // how to use
    
    <DIV id=XY></DIV>
    
    });
    返回页面顶部功能
     $(document).ready(function() 
    {
     $('a[href*=#]').click(function() 
    {
    if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'')
     && location.hostname == this.hostname) 
    {
     var $target = $(this.hash);
     $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
     if ($target.length) 
    {
     var targetOffset = $target.offset().top;
     $('html,body').animate({scrollTop: targetOffset}, 900);
     return false;
     }
    }
     });
    
     // how to use
     <A name=top></A>
     <A href="#top">go to top</A>
     });
     页面样式切换
     $(document).ready(function() 
    {
     $("a.Styleswitcher").click(function() 
    {
     $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));
    });
    // how to use
     <LINK href="default.css" type=text/css rel=stylesheet>
     // the links
     <A class=Styleswitcher href="#" rel=default.css>Default Theme</A>
    
    <A class=Styleswitcher href="#" rel=red.css>Red Theme</A>
    <A class=Styleswitcher href="#" rel=blue.css>Blue Theme</A>
    });
     预加载图片
     $(document).ready(function() 
    {
     jQuery.preloadImages = function()
     {
     for(var i = 0; i").attr("src", arguments[i]);
     }
    };
    
    // how to use
    $.preloadImages("image1.jpg");
    
     });
    禁止右键点击
    
     $(document).ready(function()
    {
    $(document).bind("contextmenu",function(e)
    {
     return false;
    });
    });
    用下面方法,可以简单又可靠的得到一个变量是否一个数组:
    Object.prototype.toString.apply(value) === '[object Array]'
  • 相关阅读:
    CMake学习笔记
    右键添加"在此处打开命令窗口"菜单
    设置默认python模块源
    添加到附加组
    Unity宏处理
    挂载windows共享文件夹
    MacOS长按无效问题
    中文Locale
    笔记本用作无线路由器
    C# Winfrom iTextSharp 导出pdf 带二维码 表格嵌套 简单Dome
  • 原文地址:https://www.cnblogs.com/laopo/p/6174583.html
Copyright © 2011-2022 走看看