繁体   English   中英

Jquery将参数传递给被调用的函数

[英]Jquery pass parameter to called function

我想通过这个:

                $('.info-top').css({position:'absolute'});

在窗口调整大小时调用thumbHover函数。 谁能告诉我怎么做?

 function thumbHover() {
            $('.thumb').hover(function () {
                    $('.info-top').text('Hover Text');
                },
                function () {
                    if (!$('.info-top').hasClass('active')) {
                        $('.info-top').text('');
                    }
                });
        }
        thumbHover();

        window.onresize = function () {
       thumbHover();
            if ($(".thumb").css("margin-bottom") === "1px") {
                $('.info-top').appendTo('#Grid');
            } else {
                $('.info-top').appendTo('#middle');
            }

    };

position值作为字符串参数传递给thumbHover函数。 检查参数是否存在并做你的事情。

window.onresize = function () {
    thumbHover("absolute");
    if ($(".thumb").css("margin-bottom") === "1px") {
        $('.info-top').appendTo('#Grid');
    } else {
        $('.info-top').appendTo('#middle');
    }
};

 function thumbHover(positionVal) {
     if (positionVal.length) {
         $('.info-top').css({
             position: positionVal
         });
     }
     $('.thumb').hover(function () {
             $('.info-top').text('Hover Text');
         },
         function () {
             if (!$('.info-top').hasClass('active')) {
                 $('.info-top').text('');
             }
         });
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM