使用jQuery在单击事件上打开图像的弹出窗口

时间:2011-06-16 17:27:43

标签: jquery jquery-ui

如果我点击一些名为“更多信息”链接的文本,我会想要打开图像的弹出窗口。 我想在那张照片上写下一些东西。我试过这样做,但我无法做到这一点..任何建议将不胜感激.. 到目前为止我已经完成了这个.. 这是我的更多信息链接

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

如果我点击More Info标签,我需要打开图像的弹出窗口。我需要写下一些东西。使用此脚本,我可以打开弹出窗口,但我需要在更多信息链接附近打开该图像..

<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 href="#" 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>

1 个答案:

答案 0 :(得分:1)

这样的东西?

小提琴:http://jsfiddle.net/2eZcd/