我看到了很多帖子,在頁面上放置jssor滑塊的多個實例。但是,我想動態添加多個滑塊,具體取決於PHP查詢和CMS中的內容。所以,頁面必須準備好處理2或20個滑塊...或更多。jssor滑塊 - 在一個頁面上的許多滑塊
有計算器上的很多帖子,顯示如何添加兩個滑塊如下...
var jssor_slider1 = new $JssorSlider$("slider1_container", options);
var jssor_slider2 = new $JssorSlider$("slider2_container", options);
...然後指給每個ID(即slider2_container)時,我指的是滑塊。但是如果我有20個滑塊(或更多),我不想爲滑塊設置20條不同的線條(或者如果有20個以上的滑塊,就不用擔心)。我寧願買點一般滑...我不寫javascript,但像(我知道這是不對的,但下面的*指的是任何#)...
var jssor_slider* = new $JssorSlider$("slider*_container", options);
我看到這篇文章... Jssor non-jquery slider dynamic amount multiple slider on one page ...但它沒有得到答覆。我將使用來自CMS的信息(我使用圖庫自定義)填充頁面和滑塊。
而且,正如我所提到的,我已經看到很多其他職位的2或3滑塊...但沒有處理未知的數字。請告訴我。
<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/js/jssor.js"></script>
<script type="text/javascript" src="/js/jssor.slider.js"></script>
<script>
jQuery(document).ready(function ($) {
var _CaptionTransitions = [];
_CaptionTransitions["L"] = { $Duration: 900, x: 0.6, $Easing: { $Left: $JssorEasing$.$EaseInOutSine }, $Opacity: 2 };
_CaptionTransitions["R"] = { $Duration: 900, x: -0.6, $Easing: { $Left: $JssorEasing$.$EaseInOutSine }, $Opacity: 2 };
_CaptionTransitions["T"] = { $Duration: 900, y: 0.6, $Easing: { $Top: $JssorEasing$.$EaseInOutSine }, $Opacity: 2 };
_CaptionTransitions["B"] = { $Duration: 900, y: -0.6, $Easing: { $Top: $JssorEasing$.$EaseInOutSine }, $Opacity: 2 };
_CaptionTransitions["ZMF|10"] = { $Duration: 900, $Zoom: 11, $Easing: { $Zoom: $JssorEasing$.$EaseOutQuad, $Opacity: $JssorEasing$.$EaseLinear }, $Opacity: 2 };
_CaptionTransitions["RTT|10"] = { $Duration: 900, $Zoom: 11, $Rotate: 1, $Easing: { $Zoom: $JssorEasing$.$EaseOutQuad, $Opacity: $JssorEasing$.$EaseLinear, $Rotate: $JssorEasing$.$EaseInExpo }, $Opacity: 2, $Round: { $Rotate: 0.8} };
_CaptionTransitions["RTT|2"] = { $Duration: 900, $Zoom: 3, $Rotate: 1, $Easing: { $Zoom: $JssorEasing$.$EaseInQuad, $Opacity: $JssorEasing$.$EaseLinear, $Rotate: $JssorEasing$.$EaseInQuad }, $Opacity: 2, $Round: { $Rotate: 0.5} };
_CaptionTransitions["RTTL|BR"] = { $Duration: 900, x: -0.6, y: -0.6, $Zoom: 11, $Rotate: 1, $Easing: { $Left: $JssorEasing$.$EaseInCubic, $Top: $JssorEasing$.$EaseInCubic, $Zoom: $JssorEasing$.$EaseInCubic, $Opacity: $JssorEasing$.$EaseLinear, $Rotate: $JssorEasing$.$EaseInCubic }, $Opacity: 2, $Round: { $Rotate: 0.8} };
_CaptionTransitions["CLIP|LR"] = { $Duration: 900, $Clip: 15, $Easing: { $Clip: $JssorEasing$.$EaseInOutCubic }, $Opacity: 2 };
_CaptionTransitions["MCLIP|L"] = { $Duration: 900, $Clip: 1, $Move: true, $Easing: { $Clip: $JssorEasing$.$EaseInOutCubic} };
_CaptionTransitions["MCLIP|R"] = { $Duration: 900, $Clip: 2, $Move: true, $Easing: { $Clip: $JssorEasing$.$EaseInOutCubic} };
var options = {
$FillMode: 2, //[Opt] The way to fill image in slide, 0 stretch, 1 contain (keep aspect ratio and put all inside slide), 2 cover (keep aspect ratio and cover whole slide), 4 actual size, 5 contain for large image, actual size for small image, default=0
$AutoPlay: true, //[Opt] Whether to auto play, this option must be set to true, default=false
$AutoPlayInterval: 4000, //[Opt] Interval (in milliseconds) to go for next slide since the previous stopped if the slider is auto playing, default=3000
$PauseOnHover: 1, //[Opt] Whether to pause when mouse over if a slider is auto playing, 0 no pause, 1 pause for desktop, 2 pause for touch device, 3 pause for desktop and touch device, 4 freeze for desktop, 8 freeze for touch device, 12 freeze for desktop and touch device, default=1
$ArrowKeyNavigation: true, //[Opt] Allows keyboard (arrow key) navigation or not, default value is false
$SlideEasing: $JssorEasing$.$EaseOutQuint, //[Opt] Specifies easing for right to left animation, default value is $JssorEasing$.$EaseOutQuad
$SlideDuration: 1200, //[Opt] Duration (swipe) for slide in milliseconds, default value is 500
$MinDragOffsetToSlide: 20, //[Opt] Minimum drag offset to trigger slide , default value is 20
//$SlideWidth: 600, //[Opt] Width of every slide in pixels, default is width of 'slides' container
//$SlideHeight: 300, //[Opt] Height of every slide in pixels, default is height of 'slides' container
$SlideSpacing: 0, //[Opt] Space between each slide in pixels, default=0
$DisplayPieces: 1, //[Opt] Number of pieces to display (the slideshow would be disabled if the value is set to greater than 1), the default=1
$ParkingPosition: 0, //[Opt] The offset position to park slide (this options applys only when slideshow disabled), default=0.
$UISearchMode: 1, //[Opt] The way (0 parellel, 1 recursive, default value is 1) to search UI components (slides container, loading screen, navigator container, arrow navigator container, thumbnail navigator container etc).
$PlayOrientation: 1, //[Opt] Orientation to play slide (for auto play, navigation), 1 horizental, 2 vertical, 5 horizental reverse, 6 vertical reverse, default value is 1
$DragOrientation: 1, //[Opt] Orientation to drag slide, 0 no drag, 1 horizental, 2 vertical, 3 either, default value is 1 (Note that the $DragOrientation should be the same as $PlayOrientation when $DisplayPieces is greater than 1, or parking position is not 0)
$CaptionSliderOptions: { //[Opt] Options which specifies how to animate caption
$Class: $JssorCaptionSlider$, //[Req] Class to create instance to animate caption
$CaptionTransitions: _CaptionTransitions, //[Req] An array of caption transitions to play caption, see caption transition section at jssor slideshow transition builder
$PlayInMode: 1, //[Opt] 0 None (no play), 1 Chain (goes after main slide), 3 Chain Flatten (goes after main slide and flatten all caption animations), default=1
$PlayOutMode: 3 //[Opt] 0 None (no play), 1 Chain (goes before main slide), 3 Chain Flatten (goes before main slide and flatten all caption animations), default=1
},
$BulletNavigatorOptions: { //[Opt] Options to specify and enable navigator or not
$Class: $JssorBulletNavigator$, //[Req] Class to create navigator instance
$ChanceToShow: 2, //[Req] 0 Never, 1 Mouse Over, 2 Always
$AutoCenter: 1, //[Opt] Auto center navigator, 0 None, 1 Horizontal, 2 Vertical, 3 Both, default=0
$Steps: 1, //[Opt] Steps to go for each nav request, default=1
$Lanes: 1, //[Opt] lanes to arrange items, default=1
$SpacingX: 8, //[Opt] Horizontal space between each item in pixel, default=0
$SpacingY: 8, //[Opt] Vertical space between each item in pixel, default=0
$Orientation: 1 //[Opt] Orientation of the nav, 1 horizontal, 2 vertical, default=1
},
$ArrowNavigatorOptions: { //[Opt] Options to specify and enable arrow navigator or not
$Class: $JssorArrowNavigator$, //[Requried] Class to create arrow navigator instance
$ChanceToShow: 1, //[Req] 0 Never, 1 Mouse Over, 2 Always
$AutoCenter: 2, //[Opt] Auto center, 0 No, 1 Horizontal, 2 Vertical, 3 Both, default=0
$Steps: 1 //[Opt] Steps to go for each navigation request, default=1
}
};
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, 1280));
else
window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();
$(window).bind("load", ScaleSlider);
$(window).bind("resize", ScaleSlider);
$(window).bind("orientationchange", ScaleSlider);
//responsive code end
});
</script>
不知道第一個選項如何工作(它看起來像只適用於slider1_container)。我看到第二個選項是如何工作的......但是對於這個例子,每個頁面可以有不同數量的滑塊(一個頁面可以有5個,另一個可以有20個,另一個可以有32個)。 使用... var containerElements = [...]; ...我不得不將每個id名稱插入到containerElement中(當你不知道你有多少元素時,這是很難的)。 – Jabbamonkey
您可以將元素ID或元素實例添加到數組中。如上所述初始化jssor滑塊。 – jssor
我明白了。所以,對於3個滑塊,我會這樣做:var containerElements = [slider1_container,slider2_container,slider3_container] ...但是,我如何爲未知數量的項目執行此操作?就是那個問題。 – Jabbamonkey