gpt4 book ai didi

jquery - 简单的 jQuery 显示更多/更少的内容

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

我有这个 jQuery 脚本,该脚本在每种情况下都会显示更多/更少按钮。我不会为小于 80 像素的内容隐藏更多/更少按钮。怎么做?谢谢

$(function(){

// The height of the content block when it's not expanded
var adjustheight = 80;
// The "more" link text
var moreText = "Show more";
// The "less" link text
var lessText = "Close";

// Sets the .more-block div to the specified height and hides any content that overflows
$(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');

// The section added to the bottom of the "more-less" div
$(".more-less").append('<a href="#" class="adjust"></a>');

$("a.adjust").text(moreText);

$(".adjust").toggle(function() {
$(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible');
// Hide the [...] when expanded
$(this).parents("div:first").find("p.continued").css('display', 'none');
$(this).text(lessText);
}, function() {
$(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden');
$(this).parents("div:first").find("p.continued").css('display', 'block');
$(this).text(moreText);
});
});

最佳答案

您可以在添加调整 div 之前检查高度的条件下包装您的代码:

$(".more-less .more-block").each(function() {
if ($(this).height() <= adjustHeight())
return;
// use $(this) as selector to do whatever you want to do
// with the elements that are higher than your threshold
});

关于jquery - 简单的 jQuery 显示更多/更少的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29842145/

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