0


Nivo Slider を使用すると、画像が元のサイズの約 2 倍に拡大され、見栄えの悪い画像になります。彼らがこれを修正する方法であるかどうか疑問に思っていました。私の画像サイズは367 x 246 px.

何が起こるかの画面は次のとおりです。 ここに画像の説明を入力

ERB を含む私の HTML は次のとおりです。

<div class="slider-wrapper up-nivo">
  <div id="slider" class="nivoSlider">
    <%= image_tag "logo.JPG", alt: "" %>
    <%= image_tag "line.JPG", alt: "" %>
    <%= image_tag "game.JPG", alt: "" %>
    <%= image_tag "leaders.JPG", alt: "" %>
    <%= image_tag "crowdFacingJim.JPG", alt: "" %>
    <%= image_tag "band.JPG", alt: "" %>
  </div>
</div>

次に、ここに私のcssがあります:

.nivoSlider {
    position:relative;
    width:100%;
    height:auto;
    overflow: hidden;
}
.nivoSlider img {
    position:absolute;
    top:0px;
    left:0px;
}
.nivo-main-image {
    display: block !important;
    position: relative !important; 
    width: 100% !important;
}

/* If an image is wrapped in a link */
.nivoSlider a.nivo-imageLink {
    position:absolute;
    top:0px;
    left:0px;
    width:100%;
    height:100%;
    border:0;
    padding:0;
    margin:0;
    z-index:6;
    display:none;
}
/* The slices and boxes in the Slider */
.nivo-slice {
    display:block;
    position:absolute;
    z-index:5;
    height:100%;
    top:0;
}
.nivo-box {
    display:block;
    position:absolute;
    z-index:5;
    overflow:hidden;
}
.nivo-box img { display:block; }

/* Caption styles */
.nivo-caption {
    position:absolute;
    left:0px;
    bottom:0px;
    background:#000;
    color:#fff;
    width:100%;
    z-index:8;
    padding: 5px 10px;
    opacity: 0.8;
    overflow: hidden;
    display: none;
    -moz-opacity: 0.8;
    filter:alpha(opacity=8);
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
}
.nivo-caption p {
    padding:5px;
    margin:0;
}
.nivo-caption a {
    display:inline !important;
}
.nivo-html-caption {
    display:none;
}
/* Direction nav styles (e.g. Next & Prev) */
.nivo-directionNav a {
    position:absolute;
    top:45%;
    z-index:9;
    cursor:pointer;
}
.nivo-prevNav {
    left:0px;
}
.nivo-nextNav {
    right:0px;
}
/* Control nav styles (e.g. 1,2,3...) */
.nivo-controlNav {
    text-align:center;
    padding: 15px 0;
}
.nivo-controlNav a {
    cursor:pointer;
}
.nivo-controlNav a.active {
    font-weight:bold;
}

これが私のテーマのcssです:

.up-nivo .nivoSlider {
    position:relative;
    background:#fff url(loading.gif) no-repeat 50% 50%;
    margin-bottom:50px;
    -webkit-box-shadow: 0px 1px 5px 0px #4a4a4a;
    -moz-box-shadow: 0px 1px 5px 0px #4a4a4a;
    box-shadow: 0px 1px 5px 0px #4a4a4a;
}
.up-nivo .nivoSlider img {
    position:absolute;
    top:0px;
    left:0px;
    display:none;
}
.up-nivo .nivoSlider a {
    border:0;
    display:block;
}

.up-nivo .nivo-controlNav {
    text-align: right;
    padding: 20px 0;
    line-height: 0;
    font-size: 0;
    color: transparent;
    margin-right: 2.5%;
    margin-top: -5%;
}
.up-nivo .nivo-controlNav a {
    display:inline-block;
    width:16px;
    height:16px;
    background:url(bulletFull.png) no-repeat;
    text-indent:-9999px;
    border:0;
    margin: 0 2px;
}
.up-nivo .nivo-controlNav a.active {
    background:url(bulletEmpty.png) no-repeat;
}

.up-nivo .nivo-directionNav a {
    display:block;
    height:80px;
    width:75px;
    text-indent:-9999px;
    border:0;
}
.up-nivo a.nivo-nextNav {
    background:url(arrowRight.png) no-repeat;
    background-position: 50% 50%;
    right:15px;
}
.up-nivo a.nivo-prevNav {
    background:url(arrowLeft.png) no-repeat;
    background-position: 50% 50%;
    left:15px;
}

.up-nivo .nivo-caption {
    font-family: Helvetica, Arial, sans-serif;
}
.up-nivo .nivo-caption a {
    color:#fff;
    border-bottom:1px dotted #fff;
}
.up-nivo .nivo-caption a:hover {
    color:#fff;
}

.up-nivo .nivo-controlNav.nivo-thumbs-enabled {
    width: 100%;
}
.up-nivo .nivo-controlNav.nivo-thumbs-enabled a {
    width: auto;
    height: auto;
    background: none;
    margin-bottom: 5px;
}
.up-nivoault .nivo-controlNav.nivo-thumbs-enabled img {
    display: block;
    width: 120px;
    height: auto;
}

nivo を起動するための js は次のとおりです。

$(window).load(function() {
    return $("#slider").nivoSlider({
      pauseTime: 10000,
      directionNav: true
    });
  });
4

1 に答える 1

0

あなたのコードの一部を見なければ、それを言うのは難しいです. cssを介して画像を保持するコンテナの幅を設定することをお勧めします。それが機能しない場合 (このプラグインの新しいバージョンでは機能するはずです)、画像自体の幅を設定します。


編集: slider-wrapper と up-nivo 内に .nivoSlider があります。nivoSlider は 100% 幅に設定されているため、コンテナー全体を埋めています。そのうちの 1 つの幅を必要に応じて設定します (パディングやマージンがある場合は、おそらく 367px 以上)。

また、各画像の幅と高さを設定する必要があります...これにより、ページのレンダリングが高速化されます。

于 2012-06-29T06:55:45.583 に答える