I need to vertically align the navigation arrows with the slide image no matter what the window width is. Currently, it's putting it at 50% of the entire slide. I'm hoping to be able to do this with CSS, but seems like it may need to be done with JavaScript. If that's the case, jQuery is okay and it just needs to support modern browsers (IE 11+).
The tricky part about this is that it needs to be at 50% of the image and not the entire container, since the text beneath the image can have various heights.
What it's currently doing:
What I need it to do: (note the nav arrows are vertically centered with the image and should be no matter what window width)
Here's a JSFiddle: https://jsfiddle.net/thebluehorse/2wuq3feb/5/
<div class="container">
<div class="list clearfix">
<div class="slide">
<img src="http://placehold.it/800x350">
<ul>
<li>Ut in integer pulvinar maiores, mi sapien litora nunc ut, neque netus in ac. Et nullam, donec sapien laoreet, ullamcorper vestibulum et sed at arcu, erat scelerisque vehicula justo nam malesuada vehicula, per nibh nibh elit justo. Tempus omnis, mattis taciti cras a.</li>
</ul>
</div>
<div class="slide">
<img src="http://placehold.it/800x350">
<ul>
<li>Lorem ipsum dolor sit amet, et hymenaeos elit orci, rutrum dolor magna pellentesque ante euismod magna, sodales turpis quos class condimentum. Integer in vel etiam. Etiam pellentesque nibh phasellus sed, eget ipsum enim sed in et at, non ligula quis egestas sed quis. Lectus vitae, lobortis vestibulum maecenas auctor lorem eros, luctus vitae aliquam aliquam ipsum ligula nascetur, habitasse eu lectus imperdiet leo. Ut est fusce class conubia nunc felis, proin aliquam vitae nunc accumsan orci. A eu erat in.</li>
<li>Ut in integer pulvinar maiores, mi sapien litora nunc ut, neque netus in ac. Et nullam, donec sapien laoreet, ullamcorper vestibulum et sed at arcu, erat scelerisque vehicula justo nam malesuada vehicula, per nibh nibh elit justo. Tempus omnis, mattis taciti cras a.</li>
</ul>
</div>
<div class="slide">
<img src="http://placehold.it/800x350">
<ul>
<li>Ut in integer pulvinar maiores, mi sapien litora nunc ut, neque netus in ac. Et nullam, donec sapien laoreet, ullamcorper vestibulum et sed at arcu, erat scelerisque vehicula justo nam malesuada vehicula, per nibh nibh elit justo. Tempus omnis, mattis taciti cras a.</li>
</ul>
</div>
</div>
</div>
<style>
.container {
position: relative;
width: 80%;
margin: auto;
}
.slide {
float: left;
height: 100%;
min-height: 1px;
}
img {
width: 100%;
display: block;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
body {
background-color: #aaa;
}
</style>
<script>
$('.list').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 1,
adaptiveHeight: true
});
</script>
Well, what about using 2 carousels? One for the images, with arrows on, and another for flowing content without arrows. It's the cleanest solution I could think of: https://jsfiddle.net/mq9avx5g/2/
It makes use of slick's asNavFor
to make both carousels act as one:
$('#list_above').slick({
infinite: true,
speed: 300,
slidesToShow: 1,
adaptiveHeight: true,
dots: false,
asNavFor: '#list_below',
});
$('#list_below').slick({
dots: true,
arrows: false,
slidesToShow: 1,
asNavFor: '#list_above',
adaptiveHeight: true,
});
You can set following way arrow key in middle of the image using JQuery.
$(window).on('load resize', function () {
changepos();
});
function changepos() {
var toppos = ($('.slick-active').find("img").height()/2);
$('.slick-arrow').css('top',toppos+'px');
}
$('.list').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 1,
adaptiveHeight: true
}).on('afterChange',function(event){
var toppos = ($('.slick-active').find("img").height()/2);
$('.slick-arrow').css('top',toppos+'px');
}).trigger('afterChange');
Working Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With