jquery - Issue with responsive height on caroufredsel image carousel -
i using caroufredsel plugin responsive images, slider getting full height of images (before resized) , leaving big gap @ bottom.
the function being called within window.resize function because need check width of window. need because number of items shown has vary, , if window below width have destroy carousel , show items.
here code:
$(document).ready(function(){ $(window).resize(function(){ var numitems; var width = $(window).width(); if(width >=769) { numitems = 5; } else { numitems = 3; } var carousel = $("#carousel"); $("#carousel").caroufredsel({ responsive : true, scroll : 1, items : { visible : numitems, width : 200 }, oncreate : function () { carousel.parent().add(carousel).css('height', carousel.children().first().height() + 'px'); } }); if (width <=480){ $("#carousel").trigger("destroy"); } }).resize();//trigger resize event on page load. });
the solution question: caroufredsel responsive height fixes height issue, can't seem combine being able check number of items , destroy/create carousel depending on width of window.
any appreciated - i'm tearing hair out here. thanks.
edit have decent solution. did change requirements ever think have worked if hadn't.
the minor requirements change instead of using variable "numitems" used plugin's inbuilt min , max items. in practical terms means number of items goes 5 > 4 > 3 browser window gets smaller, nicer jumping 5 3 anyway.
i combined answers following 2 questions:
caroufredsel responsive height
need conditional jquery responsive site
this managed working. here's code ended with:
$(document).ready(function(){ function imagecarousel() { var carousel = $('#carousel'); var width = $(window).width(); if(width <=480) { carousel.trigger('destroy'); } else { carousel.caroufredsel({ auto: true, responsive: true, height : 'auto', scroll: { items : 1 }, swipe: { ontouch: true, items: 3 }, items : { visible : { min : 3, max : 5 }, width : 200 }, oncreate : function () { carousel.parent().add(carousel).css('height', carousel.children().first().height() + 30 + 'px'); } }); } $("#prev").on("click", function(){ $("#carousel").trigger("prev"); }); $("#next").on("click", function(){ $("#carousel").trigger("next"); }); }; var resizetimer; $(window).resize(function() { cleartimeout(resizetimer); resizetimer = settimeout(imagecarousel, 0); }).resize(); });
hope comes in handy someone.
Comments
Post a Comment