【问题标题】:Can make jQuery 100% width whilst keeping animation可以在保持动画的同时使 jQuery 100% 宽度
【发布时间】:2019-07-26 00:13:05
【问题描述】:

我遇到了无法正常工作的幻灯片问题。

基本上我有两张图片,我需要它们是整个页面宽度(100%)。然后,当浏览器重新调整大小/缩小时,我需要它们保持在 div 的中心/顶部,但边缘会被裁剪掉。

我已经设法让它与第一个 div 标签一起工作,但是一旦它动画调整大小的能力就会停止,我只是得到一个水平滚动条。

有什么想法吗?我卡住了!

#animatedbannerkitchen {
    float: left;
    height: 381px;
    width: 100%;
    position: relative;
    margin-bottom: 20px;
}
.slideshow {
    float: left;
    height: 381px;
    width: 100%;
    position: relative;
    margin-bottom: 20px;
}
#bannerone {
    background-image: url(purchase-tableware.jpg);
    background-repeat: no-repeat;
    background-position: center top;
    float: left;
    width: 100%;
    position: relative;
    height: 381px;
    background-size: cover; 
}
#bannertwo {
    background-image: url(tasty-plate.jpg);
    background-repeat: no-repeat;
    background-position: center top;
    float: left;
    width: 100%;
    position: relative;
    height: 381px;
    background-size: cover; 
}






 <!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.74.js"></script>

<!--  initialize the slideshow when the DOM is ready scrollLeft -->
<script type="text/javascript"> 
$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'fade',
        speed: 1500,
         slideResize: false,
        timeout: 7000// choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
});
</script>

最后是正文内容

<div id="animatedbannerkitchen">
  <div class="slideshow">
    <div id="bannerone"></div>
    <div id="bannertwo"></div>    
  </div>
</div>

任何帮助将不胜感激

【问题讨论】:

  • 如果我删除了 slidshow div,banner1+2 都可以完美调整大小但不设置动画。

标签: jquery width


【解决方案1】:
$(window).onLoad(function() {
  var windowWidth = $(window).width();
  $('#bannerone').css('background-width', windowWidth);
  $('#bannertwo').css('background-width', windowWidth);
});

或者

$(window).onLoad(function() {
  var bannerOneWidth= $('#bannerone').width();
  $('#bannerone').css('background-width', bannerOneWidth);
  var bannerTwoWidth= $('#bannertwo').width();
  $('#bannertwo').css('background-width', bannerTwoWidth);
});

【讨论】:

  • 嗨,感谢您的帮助,但我将此添加到 jquery 中,但它似乎不起作用。调整窗口大小时,幻灯片横幅 2 无法 100% 适合
猜你喜欢
  • 1970-01-01
  • 2016-12-17
  • 2011-04-14
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-21
  • 2011-03-03
相关资源
最近更新 更多