[英]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.