你好,我想用這個slider但我有一個問題。根據屏幕尺寸使用不同的js規則
我的目標是展示從我8個圖像名.web類圖像時,我的屏幕有一個768px最小寬度和從我8個圖像只顯示.phone類圖像時,我的屏幕上有一個MAX-寬度:768px。
所以當我們看到4張圖片時,我們會回到第一張。
隨着我的CSS技術我可以看到白色背景從圖像5到8的而不是看到背景圖像1到4
@media only screen and (min-width: 768px) {
li.web { display: block; }
li.phone { display: none; }
}
@media only screen and (max-width: 768px) {
li.web { display: none; }
li.phone { display: block; }
}
<ul id="cbp-bislideshow" class="cbp-bislideshow">
<li class="web"> <img src="https://placehold.it/250x250" alt="image01" /></li>
<li class="web"> <img src="https://placehold.it/250x250" alt="image02" /></li>
<li class="web"> <img src="https://placehold.it/250x250" alt="image03" /></li>
<li class="web"> <img src="https://placehold.it/250x250" alt="image04" /></li>
<li class="phone"><img src="https://placehold.it/150x150" alt="image05" /></li>
<li class="phone"><img src="https://placehold.it/150x150" alt="image06" /></li>
<li class="phone"><img src="https://placehold.it/150x150" alt="image07" /></li>
<li class="phone"><img src="https://placehold.it/150x150" alt="image08" /></li>
</ul>
感謝
UPDATES
修改我HTML ,JS & CSS的一部分,但它並不適用於工作,這是我的修改:
CSS
/* Slider */
.cbp-bislideshow.web,
.cbp-bislideshow.phone
{ list-style: none; width: 100%; height: 100%; position: fixed; top: 0; left: 0; z-index: -1; padding: 0; margin: 0; }
.cbp-bislideshow.web li,
.cbp-bislideshow.phone li
{ position: absolute; width: 101%; height: 101%; top: -0.5%; left: -0.5%; opacity: 0; -webkit-transition: opacity 1s; -moz-transition: opacity 1s; transition: opacity 1s; }
.backgroundsize .cbp-bislideshow.web li,
.backgroundsize .cbp-bislideshow.phone li
{ -webkit-background-size: cover; -moz-background-size: cover; background-size: cover; background-position: center center; }
.backgroundsize.cbp-bislideshow.web li img,
.backgroundsize.cbp-bislideshow.phone li img,
{ display: block; }
.cbp-bislideshow.web li img,
.cbp-bislideshow.phone li img
{ display: none; width: 100%; }
.no-js.no-backgroundsize .cbp-bislideshow.web li:first-child,
.no-js.no-backgroundsize .cbp-bislideshow.phone li:first-child
{ opacity: 1; }
.no-js.backgroundsize .cbp-bislideshow.web li:first-child img,
.no-js.backgroundsize .cbp-bislideshow.phone li:first-child img
{ display: block; }
@media only screen and (min-width: 768px) { .cbp-bislideshow.web { display:block; } .cbp-bislideshow.phone { display:none; } }
@media only screen and (max-width: 768px) { .cbp-bislideshow.web { display:none; } .cbp-bislideshow.phone { display:block; } }
JS
var cbpBGSlideshow=(function(){var l=$("#cbp-bislideshow-web, #cbp-bislideshow-phone"),g=l.children("li"),n=g.length,f=$("#cbp-bicontrols"),c={$navPrev:f.find("span.cbp-biprev"),$navNext:f.find("span.cbp-binext"),$navPlayPause:f.find("span.cbp-bipause")},h=0,e,k=true,b=3500;function m(o){l.imagesLoaded(function(){if(Modernizr.backgroundsize){g.each(function(){var p=$(this);p.css("background-image","url("+p.find("img").attr("src")+")")})}else{l.find("img").show()}g.eq(h).css("opacity",1);j();a()})}function j(){c.$navPlayPause.on("click",function(){var o=$(this);if(o.hasClass("cbp-biplay")){o.removeClass("cbp-biplay").addClass("cbp-bipause");a()}else{o.removeClass("cbp-bipause").addClass("cbp-biplay");i()}});c.$navPrev.on("click",function(){d("prev");if(k){a()}});c.$navNext.on("click",function(){d("next");if(k){a()}})}function d(q){var p=g.eq(h);if(q==="next"){h=h<n-1?++h:0}else{if(q==="prev"){h=h>0?--h:n-1}}var o=g.eq(h);p.css("opacity",0);o.css("opacity",1)}function a(){k=true;clearTimeout(e);e=setTimeout(function(){d("next");a()},b)}function i(){k=false;clearTimeout(e)}return{init:m}})();
HTML
<div class="container">
<div class="main">
<ul id="cbp-bislideshow-web" class="cbp-bislideshow web">
<li><img src="index/img/1.jpg" alt="image01"/></li>
<li><img src="index/img/2.jpg" alt="image02"/></li>
<li><img src="index/img/3.jpg" alt="image03"/></li>
<li><img src="index/img/4.jpg" alt="image04"/></li>
</ul>
<ul id="cbp-bislideshow-phone" class="cbp-bislideshow phone">
<li><img src="index/img/5.jpg" alt="image05"/></li>
<li><img src="index/img/6.jpg" alt="image06"/></li>
<li><img src="index/img/7.jpg" alt="image07"/></li>
<li><img src="index/img/8.jpg" alt="image08"/></li>
</ul>
<div id="cbp-bicontrols" class="cbp-bicontrols">
<span class="cbp-binext"></span>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="index/js/jquery.imagesloaded.min.js"></script>
<script src="index/js/cbpBGSlideshow.min.js"></script>
<script>$(function() { cbpBGSlideshow.init(); });</script>
有UL上的CSS?顯示任何不應該留下空白。我的猜測是幻燈片正在計算所有圖像加載時的寬度。您可能需要在更改它時執行重新計算。不知道更多細節,不可能真正幫助你。 – epascarello
構建兩個完全分離的滑塊,並隱藏一個或另一個,而不是隱藏單個圖像。 – Blazemonger
我試圖複製滑塊並一個一個隱藏,但沒有運氣,也許我做錯了? –