gpt4 book ai didi

jquery - css - jQuery 使用一个元素到另一个元素的内联样式,可以使用类值来实现,但需要使用内联值

转载 作者:太空宇宙 更新时间:2023-11-03 18:46:46 25 4
gpt4 key购买 nike

这是我的代码

      var test = jQuery(".ls-wp-fullwidth-container").css("height");
jQuery('#main-home').css({ top: test.height() });

由于变量具有 .css("height"); 以上不起作用在其中,当我删除它时它会起作用,它看起来像这样

      var test = jQuery(".ls-wp-fullwidth-container");
jQuery('#main-home').css({ top: test.height() });

它返回顶部:0;由于样式表中未定义高度。

如果我运行下面的代码,它会返回 .ls-wp-fullwidth-container 的内联样式

      jQuery(".ls-wp-fullwidth-container").css("height");
alert(jQuery(".ls-wp-fullwidth-container").css("height"));

我知道只需要做一点调整,但我不确定是什么。

如果我进入我的样式表并将高度添加到类 .ls-wp-fullwidth-container 中,那么使用第一段代码就可以完美地工作..但是我需要返回内联值..

最佳答案

试试这个:

var test = jQuery(".ls-wp-fullwidth-container");

var height = test.css("height");

// You can check the height here
alert(height);

jQuery('#main-home').css({ top: height });

// Also in place of css use .offset()
jQuery('#main-home').offset({ top: height });

关于jquery - css - jQuery 使用一个元素到另一个元素的内联样式,可以使用类值来实现,但需要使用内联值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209411/

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