开发者

Open a popup window of an image on a click event using jQuery

There is a UI where I want to open a popup window of an image if I click on some text called More Info link.. I want to write down something on that image. I tried doing that but I am not able to do it.. Any suggestions will be appreciated.. So far i have done this.. This is my more info link

<a href="#?w=700" rel="popup2" class="poplight">
                    <div class="meta">
                    <div class="show-more-info">+ More Info</div>
                    </div>
                    </a>

And I need to open a popupwindow of the image if i click on More Info tag. And I need to write down something. And with this script I am able to open popup window but I need to open that image near More Info link..

<script type="text/javascript">

$(document).ready(function(){                                  

    //When you click on a link with class of poplight and the href starts with a # 

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

        var popID = $(this).attr('rel'); //Get Popup Name

        var popURL = $(this).attr('href'); //Get Popup href to define size



        //Pull Query & Variables from href URL

        var query= popURL.split('?');

        var dim= query[1].split('&');

        var popWidth = dim[0].split('=')[1]; //Gets the first query string value



        //Fade in the Popup and add close button

        $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a hre开发者_Go百科f="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');



        //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css

        var popMargTop = ($('#' + popID).height() + 80) / 2;

        var popMargLeft = ($('#' + popID).width() + 80) / 2;



        //Apply Margin to Popup

        $('#' + popID).css({ 

            'margin-top' : -popMargTop,

            'margin-left' : -popMargLeft

        });



        //Fade in Background

        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.

        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 



        return false;

    });





    //Close Popups and Fade Layer

    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...

        $('#fade , .popup_block').fadeOut(function() {

            $('#fade, a.close').remove();  

    }); //fade them both out



        return false;

    });





});

</script>


Something like this?

fiddle: http://jsfiddle.net/2eZcd/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜