zoukankan      html  css  js  c++  java
  • Jquery插件学习

    ---插件一---------------------------------------------------------------

    1、首先了解下这里http://api.jquery.com/jQuery.extend/

    2、定义插件内容

        (function($) {
            $.fn.foobar = function(options) {  //footbar定义为插件的名字 function参数可以有多个
                var settings = {
                    value: 5,
                    name: "pete",
                    bar: 655
                };
                if (options) {
                    $.extend(settings, options);
                };

               //这里我们定义当单击对象时候发生的事情
                $("#Button1").click(function() {
                    alert(settings.value);
                });
            }
        })(jQuery);

    3、如何使用插件

       //对象调用插件,当点击对象时候,发生插件包里的单击事件,

       $(function() {
               $("#Button1").foobar({  
                value: 8
               } );
        })

    4、html内容

        <div>
            <input id="Button1" type="button" value="button" />
            <input id="Text1" type="text" />
            <div id="show"></div>
        </div>

    ---插件二------------------------------------------------------------------

    1、遮罩层的定义

     (function($) {
                $.fn.extend({
                    showT: function() { $("#MaskID").show(); this.show("slow"); },
                    hideT: function() { $("#MaskID").hide(); this.hide("slow"); }
                });
                $.fn.dialog = function(options) {
                    var settings = {

                        oWidth: 100 + "px",
                        oHeight: 100 + "px"
                    };

                    if (options) {
                        $.extend(settings, options);
                    };

                    MaskDiv = function(el) {
                        var wnd = $(window);
                        var doc = $(document);
                        //alert(doc.height());
                        if (wnd.height() > doc.height()) {  //当高度少于一屏
                            wHeight = wnd.height();
                        }
                        else {   //当高度大于一屏
                            wHeight = doc.height();
                        }
                        //创建遮罩背景

                        $("body").append("<div ID=MaskID  ></div>");
                        $("body").find("#MaskID").width(wnd.width()).height(wHeight).css({ display: "none", position: "absolute", top: "0px", left: "0px", background: "#ccc", filter: "Alpha(opacity=90);", opacity: "0.3", zIndex: "10000" });
                    }

                    MaskDiv(this);
                    this.width(settings.oWidth).height(settings.oHeight);
                    sPosition = function(obj) {
                        var MyDiv_w = parseInt(obj.width());
                        var MyDiv_h = parseInt(obj.height());

                        var width = parseInt($(document).width());
                        var height = parseInt($(window).height());
                        var left = parseInt($(document).scrollLeft());
                        var top = parseInt($(document).scrollTop());

                        var Div_topposition = top + (height / 2) - (MyDiv_h / 2); //计算上边距
                        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2); //计算左边距
                        return Array(Div_topposition, Div_leftposition);
                    }
                    PosT = sPosition(this);
                    this.css({ position: "absolute", top: PosT[0] + "px", left: PosT[1] + "px", background: "#FFCC66", zIndex: "10001" });
                    return this;
                }


            })(jQuery);

    2、调用遮罩

    $(function() {

            //初始化弹出框
            $('#DivDialog').dialog({
                oWidth: 200 + "px",
                oHeight: 200 + "px"
            });
            $("#Button1").click(function() {
                 $('#DivDialog').showT();//open dialog
                });
                $("#dd").click(function() {
                     $('#DivDialog').hideT();//hide
                });

            })

    3、html文件格式

        <div>
            <input id="Button1" type="button" value="button" />
        </div>
        <div id="DivDialog" style='display: none'>
            <div style="text-align: right">
                <a href="#" id="dd">[x]</a></div>
            对方答复
        </div>

  • 相关阅读:
    在 VS14 上安装 Visual F# Power Tools
    关于sources.list和apt-get [转载]
    MATLAB中导入数据:importdata函数
    部分 CM11 系统 Android 平板执行植物大战僵尸 2 黑屏的解决的方法
    html5视频播放
    用GruntJS合并、压缩JS文件
    Linux/UNIX进程控制(1)
    TCP/IP协议,HTTP协议
    php 求水仙花数优化
    使用LAMP创建基于wordpress的个从博客站点
  • 原文地址:https://www.cnblogs.com/yidianfeng/p/1781073.html
Copyright © 2011-2022 走看看