开发者

Problematic function call in Jquery

开发者 https://www.devze.com 2023-02-23 12:46 出处:网络
This works: $(\"a.lightbox\").click(function (e) { //var heading = $(this).attr(\'rel\') // hide scrollbars!

This works:

$("a.lightbox").click(function (e) {
    //var heading = $(this).attr('rel')
    // hide scrollbars!
    $('body').css('overflow-y', 'hidden')
    $('body').css('overflow-x', 'hidden');
    $('<div id="lightbox_overlay"></div>').appendTo('body');    
    return false;
});

But this doesn't

function showImage(){
    $('body').css('overflow-y', 'hidden')
    $('body').css('overflow-x', 'hidden');
    $('<div id="lightbox开发者_Python百科_overlay"></div>').appendTo('body');
}

$("a.lightbox").click(function (e) {
    showImage();
    return false;
});

Any help will be greatly appreciated


Does this work?

(function($) {

    function showImage() {

        $("body").css({

            "overflow-y" : "hidden",
            "overflow-x" : "hidden" 

        });

        $('<div id="lightbox_overlay"></div>').appendTo("body");

    }

    $("a.lightbox").click(function(e) {

        e.preventDefault();
        showImage();

    });

})(jQuery);
0

精彩评论

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

关注公众号