gpt4 book ai didi

jquery 将 $(this) 插入一个单独的函数

转载 作者:行者123 更新时间:2023-12-01 07:59:52 25 4
gpt4 key购买 nike

嘿,我有一个像这样设置的函数:

var smallerHeight_css = function() {
var sizeVariable = ".06";
var smallerHeight_height = DISCOVERY_GROUNDUP.groundupHEIGHT * sizeVariable;

$(this).find(".groundup-hotspotCircle").css({
height:smallerHeight_height,
width:"auto"
});
$(this).find(".groundup-hotspotPadding, .groundup-hotspotContent-container").css({
height:smallerHeight_height
});
$(this).find(".groundup-hotspotTitle").css({
height:smallerHeight_height -5,
width:smallerHeight_height - 5,
borderRadius:smallerHeight_height,
top:"50%",
left:"50%",
marginLeft:((smallerHeight_height -5) * ".5") * -1,
marginTop:((smallerHeight_height -5) * ".5") * -1
});
$(this).find(".groundup-hotspotPadding").css({
width:0
});
$(this).find(".groundup-hotspotContent-container").css({
width:0
});
};

我希望能够在 .each 函数中调用它,但我不确定如何引用 $(this)。现在我已经这样设置了,但它不起作用。任何帮助都会很棒!

if (DISCOVERY_GROUNDUP.groundupHEIGHT < DISCOVERY_GROUNDUP.groundupWIDTH) {
$(".groundup-hotspot-container").each(function() {
if ( $(this).hasClass("collapsed") ) {
smallerHeight_css();
} else if ( $(this).hasClass("expanded") ) {

}
});

}

最佳答案

也许传入$(this)作为参数:

if (DISCOVERY_GROUNDUP.groundupHEIGHT < DISCOVERY_GROUNDUP.groundupWIDTH) {
$(".groundup-hotspot-container").each(function() {
if ( $(this).hasClass("collapsed") ) {
smallerHeight_css($(this));
} else if ( $(this).hasClass("expanded") ) {
//do something
}
});

}

//see the parameter, el?
var smallerHeight_css = function(el) {
var sizeVariable = ".06";
var smallerHeight_height = DISCOVERY_GROUNDUP.groundupHEIGHT * sizeVariable;

el.find(".groundup-hotspotCircle").css({
height:smallerHeight_height,
width:"auto"
});
el.find(".groundup-hotspotPadding, .groundup-hotspotContent-container").css({
height:smallerHeight_height
});

//.....etc....

关于jquery 将 $(this) 插入一个单独的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20820227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com