gpt4 book ai didi

jquery - 将这个打开到最大尺寸的正确方法是什么?

转载 作者:可可西里 更新时间:2023-11-01 13:08:09 28 4
gpt4 key购买 nike

又是我的 fiddle 。如果您单击 this fiddle 中的元素,它将滑开到特定高度。

fiddle 显示带有一些“摘要文本”的部分(就像您单击打开时对完整加载文本的预览)。

我的意图是,我在单击该元素时加载“完整消息”,然后将其滑动打开的时间与内容到达的距离一样长。

我的第一个想法是:

  • 点击,通过 AJAX 或其他方式加载全文。否则
  • 将这段全文放入一个隐藏的容器中
  • 获取隐藏容器的高度
  • 隐藏“摘要文本”容器,显示“全文”容器
  • 向上滚动到测量高度
  • 利润。

好吧,我想这会奏效。但是我的程序员的感觉告诉我这是错误的做法。我不知道“长文”有多长,所以可能只有几行,但也可以是整篇文章。

那么哪种方法最适合滑动 <section>只要它的内容去就可以打开?

作为关闭<section>有一个固定的高度,再关闭它就不会那么难了。

HTML:

<section class="mbox mbox_closed" id="effect1_1">
<h2>BUSINESS PC</h2>

<div class="mbox_content" id="effect2_1">
<h3>Lorem ipsum dolor sit amet, consetetur sadipscing elitr!
<span>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</span>
</h3>

<p>Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<hr>
<img src="http://www.club-3d.com/tl_files/club3d/uploads/en/content/Accesories/CAC-1052/cac-1052_use_01.png" alt="Testbild">
<!--<div class="mbox_bar"></div>-->
</section>

CSS:

@import url(http://fonts.googleapis.com/css?family=Open+Sans);
body, html {
height:100%;
padding:0;
margin:0;
background:#5cafff;
font-family:'Open Sans', sans-serif;
}
.mbox {
z-index: 1;
margin: 2em;
position:relative;
background: #ff1a00;
background: linear-gradient(to right, #ffffff 33%, #ff1a00 100%);
border: 1px solid #fff;
height:200px;
clear:both;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=90)";
filter: alpha(opacity=90);
-moz-opacity: 0.9;
-khtml-opacity: 0.9;
opacity: 0.9;
}
.mbox_closed:hover {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
-moz-opacity: 1.0;
-khtml-opacity: 1.0;
opacity: 1.0;
-moz-box-shadow: 0px 0px 12px 8px rgb(128,128,128);
-webkit-box-shadow: 0px 0px 12px 8px rgb(128,128,128);
box-shadow: 0px 0px 12px 8px rgb(128,128,128);
}
.mbox_active {
z-index: 1;
margin: 2em;
position:relative;
background: #ff1a00;
background: linear-gradient(to right, #ffffff 33%, #ff1a00 100%);
border: 1px solid #fff;
height:200px;
clear:both;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
-moz-opacity: 1.0;
-khtml-opacity: 1.0;
opacity: 1.0;
}
.mbox * {
padding:0;
margin:0;
}
.mbox_content {
z-index: 2;
float:left;
padding: 20px;
background: #ffffff;
width:60%;
height:160px;
overflow: hidden;
overflow-y: hidden;
}
.mbox img {
z-index:-1;
position:absolute;
right:0;
max-height:100%;
}
.mbox hr {
z-index: 2;
float:left;
width: 0;
height: 0;
border-style: solid;
margin-top: 30px;
border-width: 15px 0 15px 20px;
border-color: transparent transparent transparent #ffffff;
}
.mbox_bar {
z-index: 2;
float:right;
width: 30;
height: 100%;
border-style: solid;
border-width: 0 10px 3px 3px;
border-color: #ffffff #ffffff #ffffff #ffffff;
}
.mbox h2 {
text-transform: uppercase;
font-weight:normal;
font-size:1em;
top:-0.7em;
left: 0.5em;
position:absolute;
color:#fff;
background:#ff1a00;
padding:0 1em;
border:1px solid #fff;
border-radius:1em;
}
.mbox_content h3 {
font-size:1.4em;
color:#666;
border-left:2px solid #ccc;
padding-left: 1em;
margin-bottom:0.5em;
}
.mbox_content h3 span {
margin-top:0.5em;
display:block;
font-size:0.7em;
text-transform: uppercase;
font-weight:normal;
}

JS:

var state = []

$(function() {

state[1] = true;

$( "#effect1_1" ).click(function() {

if ( state[1] ) {
$( "#effect1_1" ).animate({
height: 600
}, 1000 );
$( "#effect2_1" ).animate({
height: 560
}, 1000 );

$( "#effect1_1" ).removeClass( "mbox_closed" ).addClass( "mbox_active" );

} else {
$( "#effect1_1" ).animate({
height: 200
}, 1000 );
$( "#effect2_1" ).animate({
height: 160
}, 1000 );

$( "#effect1_1" ).removeClass( "mbox_active" ).addClass( "mbox_closed" );

}
state[1] = !state[1];
});
});

最佳答案

动画时,使用scrollHeight属性:

Height of the scroll view of an element; it includes the element padding but not its margin.

所以你的 JS 代码应该是这样的:

var state = []

$(function() {

state[1] = true;

$( "#effect1_1" ).click(function() {

if ( state[1] ) {
$( "#effect1_1" ).animate({
height: $( "#effect2_1" ).prop( "scrollHeight" )
}, 1000 );
$( "#effect2_1" ).animate({ // since scrollHeight brings the padding too, we need to remove it so the div not 'pops out' the container
height: $( "#effect2_1" ).prop( "scrollHeight" ) - parseInt( $( "#effect2_1" ).css( "padding-top" ), 10 ) - parseInt( $( "#effect2_1" ).css( "padding-bottom" ), 10 )
}, 1000 );

$( "#effect1_1" ).removeClass( "mbox_closed" ).addClass( "mbox_active" );

} else {
$( "#effect1_1" ).animate({
height: 200
}, 1000 );
$( "#effect2_1" ).animate({
height: 160
}, 1000 );

$( "#effect1_1" ).removeClass( "mbox_active" ).addClass( "mbox_closed" );

}
state[1] = !state[1];
});
});

已更新 fiddle .

关于jquery - 将这个打开到最大尺寸的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29630390/

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