2014-04-24 107 views
17

http://kenwheeler.github.io/slick/如何更改滑動旋轉木馬上幻燈片的寬度和高度?

一位朋友建議我使用Ken Wheeler的Slick旋轉木馬,我決定嘗試一下。我遇到了一些問題。首先,幻燈片不像他們應該那樣「彼此重疊」。它們被垂直堆疊。當第一張幻燈片淡入時,它位於正確的位置,但是,當第二張幻燈片淡入時,它低於第一張幻燈片的位置。另請注意,在第一張幻燈片上,右邊框被切斷,在第二張幻燈片上,除左邊框之外的所有內容都被切斷。

第二個問題是,我似乎無法改變幻燈片的寬度或高度。它們都將是相同的尺寸。 (他們在我的CSS文件中的「特色」類設置。)

我在做什麼錯?

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <title>BaseCMD :: Home</title> 
    <meta name="description" content="If it\s related to video games, you can find it here." /> 
<meta name="keywords" content="video games, microsoft, xbox, xbox 360, xbox one, sony, playstation, nintendo, wii, wii u, ds, league, console, platform, reviews, resources, players, teams, forums, servers, blog, base command, basecmd" /> 

    <link href="http://localhost/basecommand/css/960.css" rel="stylesheet" type="text/css" /> 
    <link href="http://localhost/basecommand/css/style.css" rel="stylesheet" type="text/css" /> 
    <link href="http://localhost/basecommand/css/foundation-icons.css" rel="stylesheet" type="text/css" /> 
    <link href="http://localhost/basecommand/css/slick.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
    <script src="http://localhost/basecommand/js/global.js"></script> 
    <script src="http://localhost/basecommand/js/slick.min.js"></script> 

</head> 

<body> 

<h1>Top Stories</h1> 

<script> 

$(document).ready(function(){ 
$('#featured-articles').slick({ 
    arrows: true, 
    autoplay: true, 
    autoplaySpeed: 3000, 
    dots: true, 
    draggable: false, 
    fade: true, 
    infinite: false, 
    responsive: [ 
    { 
    breakpoint: 620, 
    settings: { 
     arrows: true 
    } 
    }, 
    { 
    breakpoint: 345, 
    settings: { 
     arrows: true 
    } 
    } 
    ] 
}); 
}); 

</script> 

      <div id="featured-articles"> 

       <div class="featured" style="background: url(attachments/56da367f9e7a66952fd1ed2e79b4b317.jpg);"> 
        <h1>Another Test Article</h1> 
        <p class="info">https://www.bungie.net/pubassets/1319/Destiny_31.png 

Lorem ipsum dolor sit amet, inani accusata et duo, ad sit veniam interpretaris. Sea scripta nostrum ex, liber fastidii ea duo. Id vim nobis option contentiones, mea probatus praesent ut. Sea ex libri...</p> 

        <h2><a href="http://localhost/basecommand/index.php/articles/Another-Test-Article/5">Read More</a></h2>  
       </div> 

       <div class="featured" style="background: url(attachments/4e683defc6aba497f347b08ac05edb14.jpg);"> 
        <h1>This Is a Test Article</h1> 
        <p class="info">https://www.bungie.net/pubassets/1319/Destiny_31.png 

Lorem ipsum dolor sit amet, inani accusata et duo, ad sit veniam interpretaris. Sea scripta nostrum ex, liber fastidii ea duo. Id vim nobis option contentiones, mea probatus praesent ut. Sea ex libri...</p> 
        <h2><a href="http://localhost/basecommand/index.php/articles/This-Is-a-Test-Article/1">Read More</a></h2>  
       </div> 

      </div> 

Slide 1 Slide 2

回答

22

我做了這個插件。有一些css干擾發生。

這是你在滑塊本身的邊界。可以使用

box-sizing: border-box 

吸收邊框寬度,或將邊框放在幻燈片的內容中。

+0

好了,擺脫了邊框的解決了這個問題堆積......但我將如何更改實際幻燈片的尺寸?我已將它設置在我的css文件中,但似乎沒有任何作用。 – ShoeLace1291

+9

這裏的正確答案是什麼?我在CSS中設置了幻燈片寬度,但js中的內聯樣式正在覆蓋它,就好像它被忽略一樣。 – mtaube

+4

我不明白這裏的正確答案在哪裏 –

37

我初始化了滑蓋的特性之一,因爲

variableWidth: true, 

然後我可以設置幻燈片到任何東西的寬度,我在CSS想跟:

.slick-slide 
{ 
width: 200px; 
} 
+0

非常有幫助,謝謝。 – Raduken

+0

這解決了我的問題。謝謝。 – davesaus

+0

這是正確的答案。 'variableWidth'解決了這個問題。 – snkv

0

基本上你需要編輯JS和添加(在這種情況下,裏面$('#featured-articles').slick({),這樣的:

variableWidth: true, 

這將讓你在你的CSS編輯寬度在那裏你可以,一般使用:

.slick-slide { 
    width: 100%; 
} 

或在這種情況下:

.featured { 
    width: 100%; 
} 
相關問題