I am trying to disable the touchEnabled option for the bxSlider library if the user has a desktop browser.
if(navigator.userAgent.match(/Chrome|Mozilla|Safari/)){
$('.theSlider').bxSlider({
touchEnabled: false
});
}
//Html slider
<ul class="theSlider">
When debugging in the developer tools console in Chrome I get touchEnabled is not defined when trying to set it to false. What am I doing wrong?
Thanks for the responses, this is the solution I managed to work out. I set a default var touchDevice as false. If the user is using a mobile device it detects and sets touchDevice to true. When I initialise the bxSlider it will take whatever touchDevice is set to, and set touchEnabled to that result.
// Enable touch events for Mobile Browsers
var touchDevice = false;
if (navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/)) {
touchDevice = true;
}
$('.theSlider').bxSlider({
touchEnabled: touchDevice
});