当前位置:编程学习 > JAVA >>

自己写的一个遮罩层插件

jquery.mask.js
[javascript]
(function($) { 
    $.fn.Popup = function() { 
        return $(this).live("click", function(e) { 
            var pop_id = $(this).attr('id').split(':')[1]; 
            var content = ""; 
            if ($(this).attr('url')) { 
                var pop_url = $(this).attr('url'); 
                var suffix = pop_url.substring(pop_url.lastIndexOf('.') + 1).toLowerCase(); 
                if (suffix == "jpg" || suffix == "png" || suffix == "gif") { 
                    content = "<img src=\"" + post_url + "\" width=600 height=600/>"; 
                    pop_url=""; 
                } 
            }else if ($(this).attr('content')) { 
                content = $.base64.encode($(this).attr('content')); 
            } 
            divOpen(pop_id, pop_url, content); 
            $('a.popin-close, #fade').live('click', function() { 
                $('#fade , .popin-block').fadeOut(function() { 
                    $('#fade').remove(); 
                }); 
                return false; 
            }); 
            function divOpen(pop_id, post_url, content) { 
                var suffix = post_url.substring(post_url.lastIndexOf('.') + 1).toLowerCase(); 
                if (!$('#' + pop_id).length) { 
                    if (post_url!="") { 
                        $.ajax({ 
                            url: post_url, 
                            type: 'POST', 
                            complete:  function(response) { 
                                $('body').append('<div id="' + pop_id + '" class="popin-block">' + response.responseText + '</div>'); 
                                // Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css 
                                var popWidth = '700'; 
                                // Fade in the Popup and add close button 
                                $('#' + pop_id).fadeIn().css({'width': Number(popWidth)}).prepend('<a href="#" class="popin-close"></a>'); 
 
                                var popMargTop = ($('#' + pop_id).height() + 80) / 2; 
                                var popMargLeft = ($('#' + pop_id).width() + 80) / 2; 
                                // Apply Margin to Popup 
                                $('#' + pop_id).css({'margin-top' : -popMargTop,'margin-left' : -popMargLeft}); 
                            }, 
                            dataType: 'text', 
                            data: {pop_id: pop_id} 
                        }); 
                    } else { 
                        $('body').append('<div id="' + pop_id + '" class="popin-block">' + conten

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,