图像大小调整。如何为jquery轮播调整图像大小?

时间:2018-08-24 20:39:50

标签: laravel image

我有

  <div id="carouselExampleIndicators" class="carousel slide my-4" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner" role="listbox">
      <div class="carousel-item active">
        <img class="d-block img-fluid" style="width:1000px; max-height:300px;" src="{{ asset('uploads/'.$carousels['0']['image'] ) }}" alt="First slide">
      </div>
      <div class="carousel-item">
        <img class="d-block img-fluid" style="width:1000px; max-height:300px;" src="{{ asset('uploads/'.$carousels['1']['image'] ) }}" alt="Second slide">
      </div>
      <div class="carousel-item">
        <img class="d-block img-fluid" style="width:1000px; max-height:300px;" src="{{ asset('uploads/'.$carousels['2']['image'] ) }}" alt="Third slide">
      </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
      <span class="carousel-control-prev-icon" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>

图像的高度不同,而且看起来不太好。如何调整图像尺寸?我的意思是,如果图像的多余部分大于宽度和高度,该如何裁剪?我使用style =“ width:1000px; max-height:300px;”,还有一些更优雅的方法吗?

更新

我使用Laravel 5.6。对于轮播,我使用3个随机乘积制作数组,这就是为什么我使用'$ carousels ['0'] ['image']'的原因,我将这些图像保存在公共/上传文件中。要显示产品图片,请使用src =“ {{asset('uploads /'.$ product-> image)}}”“。

我的索引函数:

public function index()
{
    $categories = Category::all();
    $products = Product::all();
    $carousels = Product::all()->random(4);

    //dd($carousels);
    return view("index", compact("products", "categories", "carousels"));
}

0 个答案:

没有答案