简体   繁体   English

Ruby on Rails:重新归档Gem和Owl Carousel jQuery插件,组合不好? 页面加载时图像尺寸问题

[英]Ruby on Rails: Refile Gem and Owl Carousel jQuery plugin, bad combination? Issues with image size on page load

I got these two working, but having trouble with the execution. 我使这两个工作正常,但执行时遇到麻烦。 I'm assuming that one of them is loading faster than the other... 我假设其中一个的加载速度比另一个...

<div class="owl-carousel">
  <% @project.project_images.each do |image| %>
    <div class="bi-item">
      <%= attachment_image_tag(image, :file, :fit, 1000, 430) %>
    </div>
  <% end %>
</div>

So I got this loop within the owl-carousel tag... and when the page loads, the images are really tiny (see first attached image)... if I drag my browser size, the images starts becoming responsive, and the size starts changing. 因此,我在owl-carousel标记中找到了这个循环……并且当页面加载时,图像真的很小(请参阅第一个附加图像)……如果我拖动浏览器大小,图像将开始响应,并且大小开始改变。 Eventually the images will get to the correct size... I'm not sure what the issue would be, or what I need to do to get this working together. 最终,图像将达到正确的尺寸...我不确定是什么问题,或者我需要做些什么才能使其协同工作。 Is my assumption correct? 我的假设正确吗? If so, how do I make it load together? 如果是这样,我如何使其一起加载?

my coffeescript 我的咖啡稿

$(document).on 'ready page:load', ->
  $(".owl-carousel").owlCarousel
    loop: true
    autoWidth: true
    lazyLoad : true

Here's a screenshot, you can see the left side, its tiny 这是屏幕截图,您可以看到左侧,它很小

在此处输入图片说明

Then when I dragged the browser a little smaller, the image resizes, gets bigger 然后,当我将浏览器拖小一点时,图像会调整大小,变得更大

在此处输入图片说明

Then resized the browser larger, it becomes normal. 然后将浏览器调整为更大的尺寸,这将成为正常现象。

在此处输入图片说明

Alright, I think I got it... 好吧,我想我明白了...

I put the owl carousel function under window.load... this solved the issue for now. 我将owl carousel函数放在window.load下...现在已经解决了这个问题。 If someone else has another solution, or something that would be better, I'd like to know it still! 如果其他人有其他解决方案,或者更好的解决方案,我仍然想知道!

$(window).load ->

  $(".owl-carousel").owlCarousel
    loop: true
    autoWidth: true
    lazyLoad : true

Thanks 谢谢

I had a similar issue this was what helped me: 我有一个类似的问题,这就是帮助我的原因:

// set owl-carousel width equals to owl-wrapper width (solves width issue on load)
function owlWrapperWidth( selector ) {
  $(selector).each(function(){
    $(this).find('.owl-carousel').outerWidth( $(this).closest( selector ).innerWidth() );
  });
}

// trigger on start and resize (solves width issue on load)
owlWrapperWidth( '.owl-wrapper' );
$( window ).resize(function() {
  owlWrapperWidth( $('.owl-wrapper') );
});

$(document).ready(function(){

  // triggers owl Carousel
  $('.owl-carousel').owlCarousel({
    stagePadding: 0,
    items: 1,
    itemsDesktop:[1000,1],
    itemsDesktopSmall:[979,1],
    itemsTablet:[768,1],
    pagination: true,
    dots: true,
    autoplay: 3000,
    loop: true
  });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM