Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change jquery bxslider options in responsive

Posted on 2013-11-12
11
Medium Priority
?
18,988 Views
Last Modified: 2014-03-17
I would like to have different settings for my slider depending on its responsive state.
for example:

var windowsize = $(window).width();

    if (windowsize < 630) {
		$('.slider-landing').bxSlider({
			minSlides: 1,
			maxSlides: 1,
			moveSlides: 1,
			mode: 'fade',
			startSlide: 0,
			captions: false
		});
		
	} else {
		$('.slider-landing').bxSlider({
			minSlides: 1,
			maxSlides: 4,
			moveSlides: 1,
			mode: 'horizontal',
			slideWidth: 280,
			startSlide: 0,
			slideMargin: 10,
			captions: true
		});
	}

Open in new window

     
On initial load of the page it seems to work fine, but when I resize the viewport the changes do not get applied to the slider?

Do I need to destroy and reload?

Thanks
0
Comment
Question by:Al4ddin2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39643339
No you just need it in a function and fire it with onresize  event.

Cd&
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39643459
Check this : http://bxslider.com/examples/reload-slider-settings

	$(document).ready(function() {

		var settings = function() {
			var settings1 = {
				minSlides: 1,
				maxSlides: 1,
				moveSlides: 1,
				mode: 'fade',
				startSlide: 0,
				captions: false
			};
			var settings2 = {
				minSlides: 1,
				maxSlides: 4,
				moveSlides: 1,
				mode: 'horizontal',
				slideWidth: 280,
				startSlide: 0,
				slideMargin: 10,
				captions: true
			};
			return ($(window).width()<630) ? settings1 : settings2;
		}

		$(window).resize(function() {
			$('.slider-landing').reloadSlider(settings);
		});
		
		$('.slider-landing').bxSlider(settings);

	});

Open in new window

0
 

Author Comment

by:Al4ddin2
ID: 39644506
Im getting a reloadSlider is not a function JS error?

My current code is:
      
      
$(document).ready(function () {
		if (pageType.val() == "tour-landing-page") {
			
			tourLandingScript();
			$(window).resize(tourLandingScript);
				
			// initiates responsive slide gallery
				
			var settings = function() {
				var settings1 = {
					minSlides: 1,
					maxSlides: 1,
					moveSlides: 1,
					mode: 'fade',
					startSlide: 0,
					captions: false
				};
				var settings2 = {
					minSlides: 1,
					maxSlides: 4,
					moveSlides: 1,
					mode: 'horizontal',
					slideWidth: 280,
					startSlide: 0,
					slideMargin: 10,
					captions: true
				};
				return ($(window).width()<630) ? settings1 : settings2;
			}
			
			$('.slider-landing').bxSlider(settings);
		
		}
	});
	
	function tourLandingScript() {
		var windowsize = $(window).width();
	
		$('.slider-landing').reloadSlider(settings);
		
		if (windowsize < 630) {
			// more mobile scripts here
		} else {
			// more desktop scripts here
		}
	}

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 82

Expert Comment

by:leakim971
ID: 39644570
	$(document).ready(function () {
		// initiates responsive slide gallery			
		var settings = function() {
			var settings1 = {
				minSlides: 1,
				maxSlides: 1,
				moveSlides: 1,
				mode: 'fade',
				startSlide: 0,
				captions: false
			};
			var settings2 = {
				minSlides: 1,
				maxSlides: 4,
				moveSlides: 1,
				mode: 'horizontal',
				slideWidth: 280,
				startSlide: 0,
				slideMargin: 10,
				captions: true
			};
			return ($(window).width()<630) ? settings1 : settings2;
		}

		var mySlider;

		var tourLandingScript = function() {
			mySlider.reloadSlider(settings);
		}

		if (pageType.val() == "tour-landing-page") {		
			mySlider = $('.slider-landing').bxSlider(settings);
			$(window).resize(tourLandingScript);
		}
	});

Open in new window

0
 

Author Comment

by:Al4ddin2
ID: 39644692
Thanks, I have applied your code on a test page and none of the settings get applied - settings1 or settings2.
It appears to be just the default.

Therefore it also doesn't change when the viewport size changes either.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39644704
YOU add the line 31 and 34, not sure why
remove them for testing, it was not the subject of your main question
0
 

Author Comment

by:Al4ddin2
ID: 39644893
Even with those lines removed it does nothing still.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39644927
where to see that?
0
 

Author Comment

by:Al4ddin2
ID: 39645081
Here i set the mode to fade and include min slides etc but none of them get applied.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<ul class="slider-landing">
  <li><img src="http://bxslider.com/images/730_200/tree_root.jpg" title="hello" alt="bye" /></li>
  <li><img src="http://bxslider.com/images/730_200/tree_root.jpg" /></li>
</ul>

<script src="js/jquery-1.9.0.js"></script>
<script src="js/jquery.bxslider.js"></script>
<script>
	$(document).ready(function () {
		// initiates responsive slide gallery			
		var settings = function() {
			var settings1 = {
				minSlides: 2,
				maxSlides: 1,
				moveSlides: 1,
				mode: 'fade',
				startSlide: 0,
				captions: true
			};
			var settings2 = {
				minSlides: 2,
				maxSlides: 4,
				moveSlides: 1,
				mode: 'fade',
				slideWidth: 280,
				startSlide: 0,
				slideMargin: 10,
				captions: true
			};
			return ($(window).width()<630) ? settings1 : settings2;
		}

		var mySlider;

		mySlider = $('.slider-landing').bxSlider(settings);
		$(window).resize(tourLandingScript);

		
		function tourLandingScript() {
			mySlider.reloadSlider(settings);
		}
	});
</script>

</body>
</html>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39645096
I miss the () after settings
and declare your var before using them
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<ul class="slider-landing">
  <li><img src="http://bxslider.com/images/730_200/tree_root.jpg" title="hello" alt="bye" /></li>
  <li><img src="http://bxslider.com/images/730_200/tree_root.jpg" /></li>
</ul>

<script src="js/jquery-1.9.0.js"></script>
<script src="js/jquery.bxslider.js"></script>
<script>
	$(document).ready(function () {
		// initiates responsive slide gallery			
		var settings = function() {
			var settings1 = {
				minSlides: 2,
				maxSlides: 1,
				moveSlides: 1,
				mode: 'fade',
				startSlide: 0,
				captions: true
			};
			var settings2 = {
				minSlides: 2,
				maxSlides: 4,
				moveSlides: 1,
				mode: 'fade',
				slideWidth: 280,
				startSlide: 0,
				slideMargin: 10,
				captions: true
			};
			return ($(window).width()<630) ? settings1 : settings2;
		}

		var mySlider;

		function tourLandingScript() {
			mySlider.reloadSlider(settings());
		}

		mySlider = $('.slider-landing').bxSlider(settings());
		$(window).resize(tourLandingScript);

		
	});
</script>

</body>
</html>

Open in new window

0
 

Expert Comment

by:lpranger
ID: 39934817
I used this solution on a site I am developing.

Everything seemed to work except when resizing teh window my captions disappeared.

I am using boostrap 3.1.1, jquery 1.10.1, bxslider 4.1

I am positioning my captions outside the ttile attribute like this


 
					<div>
						<img src="walk-fpo-800.jpg" alt="Partner">
						<div class='bx-caption'>
							<a href=''><span>Top Picks June 14th<br><span class='white-title'>12am - 10pm</span></span> 
							<span class='head'>Flag day - Light the museum pink <i class='fa fa-caret-square-o-right'></i></span></a>
						</div>
					</div>

Open in new window


Is this the title attribute problem? DO I need to give you more on this?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question