我已经配置了带有字幕的滑块,因为我喜欢它们,并且所有功能都在屏幕的左侧完美运行,但我希望它能够居中。
我一直在寻找答案,并在多个主题中找到了添加' margin:0 auto;'滑动容器将成功。但是在我的情况下,当我添加' margin:0 auto;'在滑块容器中,它确实将容器移动到中心,但是它停止工作,在我身上发生了一些阻塞,如果它们看起来很块,则滑动。
删除边距设置会修复滑块并将其放回左对齐位置,这样其他所有内容似乎都能正常工作,我只能将它放在中间并正常工作。
<script>
jQuery(document).ready(function ($) {
var _CaptionTransitions = [];
_CaptionTransitions["L"] = {$Duration:900,$Zoom:1,$Easing:$JssorEasing$.$EaseInCubic};
var options = {
$AutoPlay: true,
$DragOrientation: 3,
$CaptionSliderOptions: {
$Class: $JssorCaptionSlider$,
$CaptionTransitions: _CaptionTransitions,
$PlayInMode: 1,
$PlayOutMode: 3
}
};
var jssor_slider1 = new $JssorSlider$("slider1_container", options);
//responsive code begin
function ScaleSlider() {
var windowWidth = $(window).width();
if (windowWidth) {
var windowHeight = $(window).height();
var originalWidth = jssor_slider1.$OriginalWidth();
var originalHeight = jssor_slider1.$OriginalHeight();
if (originalWidth / windowWidth > originalHeight / windowHeight) {
jssor_slider1.$ScaleHeight(windowHeight);
}
else {
jssor_slider1.$ScaleWidth(scaleWidth);
}
}
else
window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|BlackBerry|IEMobile)/)) {
$(window).bind('resize', ScaleSlider);
}
else {
$(window).bind("orientationchange", ScaleSlider);
}
//responsive code end
});
</script>
> <!-- Jssor Slider Begin -->
> <!-- You can move inline styles to css file or css block. -->
> <div id="slider1_container" style="position: relative; margin: 0 auto; width: 600px; height: 480px;">
> <!-- Slides Container -->
> <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width:600px; height:480px; overflow: hidden;">
> <div> <img u="image" src="portfolio/synthetic and teak deck.jpg" />
> <div u="caption" t="L" style="position: absolute;
> top: 125px; left: 125px; width: 350px;height: 50px;"><Code>Synthetic and teak decking</code>
> </div>
> </div>
> <div> <img u="image" src="portfolio/teak pool deck.jpg" />
> <div u="caption" t="L" style="position: absolute;
> top: 125px; left: 125px; width: 350px;height: 50px;"><code>Teak decking around the pool</code>
> </div>
> </div>
提前感谢任何帮助并指出我正确的方向
答案 0 :(得分:0)
代码中有错误,
请替换
jssor_slider1.$ScaleWidth(scaleWidth);
与
jssor_slider1.$ScaleWidth(windowWidth);
注意'margin:0 auto;'仅当父元素比元素宽时,才会将元素中心与其父元素对齐。因此,在全屏滑块的情况下,它将无法工作。这是一个技巧,请将滑块放在一个包装器中,如下所示,
<div style="position: relative; width: 100%; background-color: #003399; overflow: hidden;">
<div style="position: relative; left: 50%; width: 5000px; text-align: center; margin-left: -2500px;">
</div>
</div>
最后,您的代码应如下所示,
<script>
jQuery(document).ready(function ($) {
var _CaptionTransitions = [];
_CaptionTransitions["L"] = { $Duration: 900, $Zoom: 1, $Easing: $JssorEasing$.$EaseInCubic };
var options = {
$AutoPlay: true,
$DragOrientation: 3,
$CaptionSliderOptions: {
$Class: $JssorCaptionSlider$,
$CaptionTransitions: _CaptionTransitions,
$PlayInMode: 1,
$PlayOutMode: 3
}
};
var jssor_slider1 = new $JssorSlider$("slider1_container", options);
//responsive code begin
//you can remove responsive code if you don't want the slider to scale along with window
function ScaleSlider() {
var windowWidth = $(window).width();
if (windowWidth) {
var windowHeight = $(window).height();
var originalWidth = jssor_slider1.$OriginalWidth();
var originalHeight = jssor_slider1.$OriginalHeight();
if (originalWidth / windowWidth > originalHeight / windowHeight) {
jssor_slider1.$ScaleHeight(windowHeight);
}
else {
jssor_slider1.$ScaleWidth(windowWidth);
}
}
else
window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();
$(window).bind("load", ScaleSlider);
$(window).bind("resize", ScaleSlider);
$(window).bind("orientationchange", ScaleSlider);
//responsive code end
});
</script>
<div style="position: relative; width: 100%; background-color: #003399; overflow: hidden;">
<div style="position: relative; left: 50%; width: 5000px; text-align: center; margin-left: -2500px;">
<!-- Jssor Slider Begin -->
<div id="slider1_container" style="position: relative; margin: 0 auto; width: 600px; height: 300px;">
<!-- Slides Container -->
<div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width:600px; height:300px; overflow: hidden;">
<div>
<img u="image" src="portfolio/synthetic and teak deck.jpg" />
<div u="caption" t="L" style="position: absolute;
top: 125px; left: 125px; width: 350px;height: 50px;">
<code>Synthetic and teak decking</code>
</div>
</div>
<div>
<img u="image" src="portfolio/teak pool deck.jpg" />
<div u="caption" t="L" style="position: absolute;
top: 125px; left: 125px; width: 350px;height: 50px;">
<code>Teak decking around the pool</code>
</div>
</div>
</div>
</div>
</div>
</div>