我正在開發的網站本質上是敏感的,即網站設計會根據瀏覽的設備進行調整。我已經使用Bootstrap框架。如何更改Jssor Image Slider的尺寸而不會丟失iPhone設備上的響應性,圖像寬高比等?
我在我的網站中使用Jssor JQuery圖片滑塊。它在所有設備和所有流行的知名瀏覽器上都可以正常工作。我面臨的唯一問題是,在iPhone上查看時,Jssor滑塊中滑動圖像的大小應更改爲尺寸460 px * 280 px
。換句話說,Jssor圖像滑塊應該比當前的尺寸略大。但是,這樣做時,滑塊中出現的圖像的高寬比應該保持不變。
此外,當在iPhone上查看網站時,圖像滑塊應該佔據整個水平屏幕。那就是圖像滑塊不應該在滑塊周圍出現任何空白區域。目前兩個垂直空白條出現在滑塊的兩側。
最初,當在PC或筆記本電腦上的瀏覽器上查看網站時,滑塊圖像的分辨率爲940 px * 370 px
,並根據它所瀏覽的設備的大小自動調整。
上述尺寸更改應該只發生在iPhone上,而不會發生在任何其他設備上。在其他設備上,它工作得非常好,非常完美。在這個過程中圖像的高寬比也不應該受到干擾。
爲了供大家參考,我將下面的滑塊的HTML代碼和jQuery代碼放在下面。所有必要的庫文件都已包含在內。
HTML代碼:
<div id="slider1_container" style="position: relative; top: 0px; left: 0px; width: 940px; height: 370px; overflow: hidden; ">
<div u="loading" style="position: absolute; top: 0px; left: 0px;">
<div style="filter: alpha(opacity=70); opacity:0.7; position: absolute; display: block; background-color: #000000; top: 0px; left: 0px;width: 100%;height:100%;">
</div>
<div style="position: absolute; display: block; background: url(img/loading.gif) no-repeat center center; top: 0px; left: 0px;width: 100%;height:100%;">
</div>
</div>
<div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 940px; height: 370px; overflow: hidden;">
<div>
<img u="image" src="http://smartrebate.eywaharvest.com/images/brands/Bud_Light_Lime_1413041685.jpg" />
<div u=caption t="*" class="captionOrange" style="position:absolute; left:350px; bottom: 40px; width:300px; height:30px;">
slideshow transition twins
</div>
</div>
<div>
<img u="image" src="http://smartrebate.eywaharvest.com/images/brands/Finlandia_1413041875.jpg" />
<div u=caption t="*" class="captionOrange" style="position:absolute; left:350px; bottom: 40px; width:300px; height:30px;">
slideshow transition twins
</div>
</div>
<div>
<img u="image" src="http://smartrebate.eywaharvest.com/images/brands/Three_Olives_1413042332.jpg" />
<div u=caption t="*" class="captionOrange" style="position:absolute;left:350px; bottom: 40px; width:300px; height:30px;">
slideshow transition twins
</div>
</div>
<div>
<img u="image" src="http://smartrebate.eywaharvest.com/images/brands/Avalon_1413041406.jpg" />
<div u=caption t="*" class="captionOrange" style="position:absolute; left:350px; bottom: 40px; width:300px; height:30px;">
slideshow transition twins
</div>
</div>
<div>
<img u="image" src="http://smartrebate.eywaharvest.com/images/brands/Brancott_1413042551.JPG" />
<div u=caption t="*" class="captionOrange" style="position:absolute;left:350px; bottom: 40px; width:300px; height:30px;">
slideshow transition twins
</div>
</div>
</div>
<div u="navigator" class="jssorb05" style="position: absolute; bottom: 16px; right: 6px;">
<div u="prototype" style="POSITION: absolute; WIDTH: 16px; HEIGHT: 16px;"></div>
</div>
<style>
.jssorb05 div, .jssorb05 div:hover, .jssorb05 .av {
background: url(img/b05.png) no-repeat;
overflow: hidden;
cursor: pointer;
}
.jssorb05 div {
background-position: -7px -7px;
}
.jssorb05 div:hover, .jssorb05 .av:hover {
background-position: -37px -7px;
}
.jssorb05 .av {
background-position: -67px -7px;
}
.jssorb05 .dn, .jssorb05 .dn:hover {
background-position: -97px -7px;
}
.jssora12l, .jssora12r, .jssora12ldn, .jssora12rdn {
position: absolute;
cursor: pointer;
display: block;
background: url(img/a12.png) no-repeat;
overflow: hidden;
}
.jssora12l {
background-position: -16px -37px;
}
.jssora12r {
background-position: -75px -37px;
}
.jssora12l:hover {
background-position: -136px -37px;
}
.jssora12r:hover {
background-position: -195px -37px;
}
.jssora12ldn {
background-position: -256px -37px;
}
.jssora12rdn {
background-position: -315px -37px;
}
.captionOrange, .captionBlack {
color: #fff;
font-size: 20px;
line-height: 30px;
text-align: center;
border-radius: 4px;
}
.captionOrange {
background: #EB5100;
background-color: rgba(235, 81, 0, 0.6);
}
.captionBlack {
font-size:16px;
background: #000;
background-color: rgba(0, 0, 0, 0.4);
}
a.captionOrange, A.captionOrange:active, A.captionOrange:visited {
color: #ffffff;
text-decoration: none;
}
a.captionOrange:hover {
color: #eb5100;
text-decoration: underline;
background-color: #eeeeee;
background-color: rgba(238, 238, 238, 0.7);
}
.bricon {
background: url(img/browser-icons.png);
}
</style>
<span u="arrowleft" class="jssora12l" style="width: 30px; height: 46px; top: 123px; left: 0px;"></span>
<span u="arrowright" class="jssora12r" style="width: 30px; height: 46px; top: 123px; right: 0px"></span>
<a style="display: none" href="http://www.jssor.com">javascript</a>
</div>
jQuery代碼:
<script>
jQuery(document).ready(function ($) {
var _SlideshowTransitions = [{ $Duration: 1200, $Opacity: 2 }];
var options = {
$AutoPlay: 1,
$AutoPlaySteps: 1,
$Idle: 3000,
$PauseOnHover: 1,
$ArrowKeyNavigation: true,
$SlideDuration: 500,
$MinDragOffsetToSlide: 20,
$SlideSpacing: 0,
$Cols: 1,
$Align: 0,
$UISearchMode: 1,
$PlayOrientation: 1,
$DragOrientation: 3,
$SlideshowOptions: {
$Class: $JssorSlideshowRunner$,
$Transitions: _SlideshowTransitions,
$TransitionsOrder: 1,
$ShowLink: true
},
$BulletNavigatorOptions: {
$Class: $JssorBulletNavigator$,
$ChanceToShow: 2,
$Steps: 1,
$Rows: 1,
$SpacingX: 10,
$SpacingY: 10,
$Orientation: 1
},
$ArrowNavigatorOptions: {
$Class: $JssorArrowNavigator$,
$ChanceToShow: 2,
$Steps: 1
}
};
var jssor_slider1 = new $JssorSlider$("slider1_container", options);
function ScaleSlider() {
var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
if (parentWidth)
jssor_slider1.$ScaleWidth(Math.min(parentWidth, 940));
else
window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|BlackBerry|IEMobile)/)) {
$(window).bind('resize', ScaleSlider);
}
});
</script>
我對某些Intranet站點的自定義導航(使用Bootstrap 3)有類似的responsivness問題,而且我只能在刪除position:absolute(和position:fixed)之後做的事情。你可以嘗試刪除位置:絕對? – nettutvikler 2014-11-03 12:54:42