I try to get a jssor slider working with 100% width (the container has a width of 70%). The problem is, that jssor only works with pixels, so if I use a slide_container with a width of 100%, the slider doesn't work any more. Is there any trick how to get this working?
5 Answers
size of 'slide_container' should be always specified with fixed pixels. the original size is fixed then, but you can scale the slider to any size.
use following code to scale the slider to width of document.body.
var jssor_slider1 = new $JssorSlider$("slider1_container", options);
//responsive code begin
//you can remove responsive code if you don't want the slider scales while window resizes
function ScaleSlider() {
var bodyWidth = document.body.clientWidth;
if (bodyWidth)
jssor_slider1.$ScaleWidth(Math.min(bodyWidth, 1920));
else
window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();
$(window).bind("load", ScaleSlider);
$(window).bind("resize", ScaleSlider);
$(window).bind("orientationchange", ScaleSlider);
//responsive code end
also, you can scale the slider to width of parent element,
var jssor_slider1 = new $JssorSlider$("slider1_container", options);
//responsive code begin
//you can remove responsive code if you don't want the slider scales while window resizes
function ScaleSlider() {
var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
if (parentWidth)
jssor_slider1.$ScaleWidth(Math.min(parentWidth, 1920));
else
window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();
$(window).bind("load", ScaleSlider);
$(window).bind("resize", ScaleSlider);
$(window).bind("orientationchange", ScaleSlider);
//responsive code end

- 6,995
- 2
- 18
- 21
-
This is now part of the "Full Width Slider" demo, right ? – paul_h Jun 14 '14 at 13:45
-
Yes, it is part of 'full width slider'. – jssor Jun 14 '14 at 22:25
-
How do you adjust the size on this guy? http://www.jssor.com/demos/nested-slider.html – Timothy Radzikowski Jun 16 '14 at 21:24
-
@jssor, i know this thead is quite old but i need help.. i feel like i've tried everything. – Timothy Radzikowski Jun 16 '14 at 21:29
-
it is with a parent slider and 3 child sliders. You can adjust size for each separately. If there is still problem, please ask a new question in details, I will workout a demo for you. – jssor Jun 16 '14 at 22:39
-
is it also possible to change the height? – Ronin Jan 14 '15 at 13:53
-
To scale, it will always keep aspect ratio. You can call jssor_slider1.$ScaleHeight instead of jssor_slider1.$ScaleWidth. – jssor Jan 15 '15 at 00:18
-
I am getting "Uncaught TypeError: Slide.$ScaleWidth is not a function". I am using jssor.slider.mini.js right now. Is there anything other scripts that i should be using? to get $ScalWidth to work? – M H May 22 '15 at 22:25
-
jssor.slider.mini.js is enough. Is it the latest version? Do you get the slider work already? – jssor May 25 '15 at 09:59
-
Hey there. Can I kindly know how I can implement this in jssor wordpress? Regards – AndrewL64 Aug 26 '16 at 20:54
jssor_slider1.$ScaleWidth(Math.min(bodyWidth, 1920));
This still limit slider to just 1920 pix wide, maximum. So at my big screen slider was not covering 100% wide. So you may need to change that 1920 to something bigger number. I did with 19200 (one zero at the end fixed all). Once I adjusted that value it now strech all the width of my screen too.

- 71
- 1
- 1
Using Bootstrap, if you have Jssor inside an X
column div
, e.g., col-lg-12
:
jssor_slider1.$ScaleWidth(
Math.max(
Math.min
(parseInt($(".col-lg 12").css("width").replace("px", "")) -
(parseInt($(".col-lg-12").css("padding-left").replace("px", "")) +
parseInt($(".col-lg-12").css("padding-right").replace("px","")))),100));

- 31
- 1
As someone noticed, there is a problem when the slider's width is lesser than its parent's width. Chrome uses the maximum size of the slider, Firefox uses the parent instead. I have found a better code, so the slider will stretch to full width. You can modify it slightly to use the parent width or the window width.
For anyone who comes looking for $ResizeCanvas. They've finally added a function that can help get the required slider size with $ScaleSize. Thanks jssor
For the latest version 25.2.0, we added a new method $ScaleSize(width, height) instead of $ResizeCanvas.
(this was first posted here)

- 23
- 5