你能帮助我改进我的代码,或者帮助我找到另一种方法来达到这个效果吗?
谢谢。
抓住要清楚。 (希望如此) https://monosnap.com/file/4US3L1T16zQ74wxGD0O0IOEq1NhAxu
(function($) {
$.fn.offsetRelative = function(top) {
var $this = $(this);
var $parent = $this.offsetParent();
var offset = $this.position();
if (!top) return offset; // Didn't pass a 'top' element
else if ($parent.get(0).tagName == "BODY") return offset; // Reached top of document
else if ($(top, $parent).length) return offset; // Parent element contains the 'top' element we want the offset to be relative to
else if ($parent[0] == $(top)[0]) return offset; // Reached the 'top' element we want the offset to be relative to
else { // Get parent's relative offset
var parent_offset = $parent.offsetRelative(top);
offset.top += parent_offset.top;
offset.left += parent_offset.left;
return offset;
}
};
$.fn.positionRelative = function(top) {
return $(this).offsetRelative(top);
};
}(jQuery));
$(function() {
$('.service2-box a').click(function() {
var k = $('.container').width();
if ($(this).closest('.service2-box').hasClass('open')) {
$(this).closest('.service2-box').removeClass('open');
$(this).closest('.service2-box').find('.contentMega').slideUp(100);
$(this).closest('.service2-box').css('padding-bottom', 0);
} else {
$('.service2-box').css('padding-bottom', 0);
$('.service2-box .contentMega').hide();
$('.service2-box').removeClass('open');
$(this).closest('.service2-box').addClass('open');
var position = $(this).closest('.service2-box').positionRelative('.displayimagesflex');
$(this).closest('.service2-box').find('.contentMega').css({
left: position.left * -1,
top: 180,
width: k
});
$(this).closest('.service2-box').find('.contentMega').slideDown(100, function() {
var h = $(this).closest('.service2-box').find('.contentMega').outerHeight() + 15;
$(this).closest('.service2-box').css('padding-bottom', h);
});
}
return false;
})
})

.displayimagesflex {
display: flex;
flex-wrap: wrap;
position: relative;
justify-content: center;
}
.service2-box .contentMega {
position: absolute;
display: none;
padding: 40px;
width: 100%;
background: #a80532;
color: #fff;
font-size: 18px;
line-height: 22px;
z-index: 10;
font-size: 16px;
line-height: 28px;
border-bottom: 1px solid #000;
}

<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row displayimagesflex">
<div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div><div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div><div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div><div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div><div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div><div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div><div class="col s4 box-wrapper service2-box">
<div class="visible-cotent">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
<a class="MORE" href="#">Clic to see more</a>
</div>
<div class="hidden-cotent contentMega">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
</div>
</div>
&#13;