自动调整照片大小问题

时间:2015-09-24 19:51:34

标签: javascript jquery html css

我找到了this名为Flickity的惊人插件,通过我设法用图像创建同步轮播的样式选项。

我无法解决的问题是如何根据设备宽度调整图像大小。我正在实现它以使用一种水平滚动页面。我应该怎么做呢?

Codepen link

HTML

<div class="gallery gallery-nav js-flickity gallerysub"
  data-flickity-options='{ "asNavFor": ".gallery-main", "contain": true, "pageDots": false, "imagesLoaded": true, "percentPosition": false, "prevNextButtons": false, "cellAlign": "left"}'>
  <div class="nav" > <img src="http://s27.postimg.org/u7fo6xssj/image.jpg"></div>
  <div class="nav" > <img src="http://s27.postimg.org/z8n28b08z/image.jpg"></div>
  <div class="nav" > <img src="http://s27.postimg.org/4sh5a6epv/image.jpg"></div>
  <div class="nav" > <img src="http://s27.postimg.org/52ontitc3/image.jpg"></div>
</div>

<div class="gallery gallery-main js-flickity gallerymain"  data-flickity-options='{"freeScroll": true, "wrapAround": true, "prevNextButtons": false, "pageDots": false, "imagesLoaded": true, "percentPosition": false}'>
  <div class="for" > <img src="http://s27.postimg.org/u7fo6xssj/image.jpg"></div>
  <div class="for" > <img src="http://s27.postimg.org/z8n28b08z/image.jpg"></div>
  <div class="for" > <img src="http://s27.postimg.org/4sh5a6epv/image.jpg"></div>
  <div class="for" > <img src="http://s27.postimg.org/52ontitc3/image.jpg"></div>
</div>

CSS

.flickity-enabled {
  position: relative;
}

.flickity-enabled:focus { outline: none; }

.flickity-viewport {
  position: relative;
  height: 100%;
}

.flickity-slider {
  position: absolute;
  width: 100%;
  height: 100%;
}

/* draggable */

.flickity-enabled.is-draggable {
  -webkit-tap-highlight-color: transparent;
          tap-highlight-color: transparent;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}

.flickity-enabled.is-draggable .flickity-viewport {
  cursor: move;
  cursor: -webkit-grab;
  cursor: grab;
}

.flickity-enabled.is-draggable .flickity-viewport.is-pointer-down {
  cursor: -webkit-grabbing;
  cursor: grabbing;
}

/* ---- previous/next buttons ---- */

.flickity-prev-next-button {
  position: absolute;
  top: 50%;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: white;
  background: hsla(0, 0%, 100%, 0.75);
  cursor: pointer;
  /* vertically center */
  -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
          transform: translateY(-50%);
}

.flickity-prev-next-button:hover { background: white; }

.flickity-prev-next-button:focus {
  outline: none;
  box-shadow: 0 0 0 5px #09F;
}

.flickity-prev-next-button:active {
  filter: alpha(opacity=60); /* IE8 */
  opacity: 0.6;
}

.flickity-prev-next-button.previous { left: 10px; }
.flickity-prev-next-button.next { right: 10px; }
/* right to left */
.flickity-rtl .flickity-prev-next-button.previous {
  left: auto;
  right: 10px;
}
.flickity-rtl .flickity-prev-next-button.next {
  right: auto;
  left: 10px;
}

.flickity-prev-next-button:disabled {
  filter: alpha(opacity=30); /* IE8 */
  opacity: 0.3;
  cursor: auto;
}

.flickity-prev-next-button svg {
  position: absolute;
  left: 20%;
  top: 20%;
  width: 60%;
  height: 60%;
}

.flickity-prev-next-button .arrow {
  fill: #333;
}

/* color & size if no SVG - IE8 and Android 2.3 */
.flickity-prev-next-button.no-svg {
  color: #333;
  font-size: 26px;
}

/* ---- page dots ---- */

.flickity-page-dots {
  position: absolute;
  width: 100%;
  bottom: -25px;
  padding: 0;
  margin: 0;
  list-style: none;
  text-align: center;
  line-height: 1;
}

.flickity-rtl .flickity-page-dots { direction: rtl; }

.flickity-page-dots .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin: 0 8px;
  background: #333;
  border-radius: 50%;
  filter: alpha(opacity=25); /* IE8 */
  opacity: 0.25;
  cursor: pointer;
}

.flickity-page-dots .dot.is-selected {
  filter: alpha(opacity=100); /* IE8 */
  opacity: 1;
}

/* external css: flickity.css */

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

body { font-family: sans-serif; }



.gallery-main img {
  display: block;
  height: 600px;
}

.gallery-nav img {
  display: block;
  height: 93px;
}

div.for {
  margin-right: 30px;
}

.gallerymain {
  margin-top: 30px;
}

.gallerysub {
  margin-top: 30px;

}

0 个答案:

没有答案