Reputation: 21
I have implemented bxslider in our site where slider has been coming in dynamic way like in while loop. Here there is dynamic code in while loop like:
$html_img = '<div class="sch_rel_img">';
if(count($node_img)>1)
{
$html_img .='<link href="'.base_path().drupal_get_path('module','demonz').'/css/jquery.bxslider.css" type="text/css" rel="stylesheet" media="screen" charset="utf-8"/>';
$html_img .='<script src="'.base_path().'sites/default/themes/demonz/js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>';
$html_img .='<script src="'.base_path().drupal_get_path('module','pubclub').'/js/jquery.searchres_bxslider.min.js" type="text/javascript" charset="utf-8"></script>';
$html_img .='<script type="text/javascript" src="'.base_path().drupal_get_path('module','pubclub').'/js/search_carousel.js" charset="utf-8"></script>';
//$html_img .="<input type='hidden' name='nid' id='nid' value='".$nid."' />";
//$car = 1;
//$html_img .='<div class="schnext" id="schnext_'.$nid.'"></div><ul class="carousel_'.$nid.'">';
$html_img .='<div class="schnext" id="schnext"></div><ul class="carousel" id="carousel_'.$nid.'">';
foreach($node_img as $img)
{
$image = $img['filepath'];
$html_img .="<li>";
$html_img .="<img src='".$image."' width='98%' height='96%' />";
$html_img .="</li>";
}
/*$html_img .= "<li><img src='".base_path()."sites/default/files/images/events/17b9e1fb62623361831924370675857fe73225b8/big-event.jpg' width='98%' height='96%' /></li>";
$html_img .= "<li><img src='".base_path()."sites/default/files/images/events/17b9e1fb62623361831924370675857fe73225b8/innquizitive_thursday_screen_ad.jpg' width='98%' height='96%' /></li>";*/
//$html_img .='</ul><div class="schprev" id="schprev_'.$nid.'"></div>';
$html_img .='</ul><div class="schprev" id="schprev"></div>';
}
$html_img .='</div>';
And my bxslider script is
<script type="text/javascript">
var slider = $(".carousel").bxSlider({
mode:'horizontal',
auto:false,
pager:false,
moveSlides:1,
nextSelector: '#schnext',
prevSelector: '#schprev'
/*nextText: 'Onward →',
prevText: '← Go back'*/
});
</script>
how to implement this thing to get multiple carousel in one page. I can't understand how to build up the js file of bxslider in dynamic way as well as above php script's code.
I tried this thing with $('.carousel').each(function() { slidercode });
but not desired result.
If any one knows about this type of solution, please help me.
Thank you
Upvotes: 2
Views: 5801
Reputation: 9397
As you have muiltiple DIVs with a unique carousel_* ID just use them for the selector.
$('#carousel_1').bxslider({ ... });
$('#carousel_2').bxslider({ ... });
...
Or if they all have the same options:
$('.carousel').each(function(index,item) {
$(item).bxslider({ ... });
});
Multiple slideshows are also explained in the docs from bxslider.
Upvotes: 4