简体   繁体   English

GSAP slider 在 IE11 和 safari 中不起作用

[英]GSAP slider not working in IE11 and safari

I integrated this slider into my website after I find that it is not working on IE11 and safari:在我发现它在 IE11 和 safari 上不起作用后,我将这个 slider 集成到我的网站中:

Here is a link to the slider's code:这是滑块代码的链接:

https://codepen.io/gvrban/pen/qjbpaa https://codepen.io/gvrban/pen/qjbpaa

IT works fine in Chrome and in IE11 I have tried changing the style but the problem persist.它在 Chrome 和 IE11 中运行良好,我尝试更改样式,但问题仍然存在。 I think it is related to the flexbox.我认为它与 flexbox 有关。

HTML part (only one slide ): HTML 零件(只有一张幻灯片):

<div class="slider">
<div class="slider-wrapper flex">
        <div class="slide flex">
        <div class="slide-image slider-link next"><img src="https://goranvrban.com/codepen/img6.jpg"><div class="overlay"></div></div>
        <div class="slide-content">
            <div class="slide-date">30.10.2017.</div>
            <div class="slide-title">LOREM IPSUM DOLOR SITE MATE, AD EST ABHORREANT</div>
            <div class="slide-text">Lorem ipsum dolor sit amet, ad est abhorreant efficiantur, vero oporteat apeirian in vel. Et appareat electram appellantur est. Ei nec duis invenire. Cu mel ipsum laoreet, per rebum omittam ex. </div>
            <div class="slide-more">READ MORE</div>
        </div>  
    </div>
</div>
<div class="arrows">
<a href="#" title="Previous" class="arrow slider-link prev"></a>
<a href="#" title="Next" class="arrow slider-link next"></a>
</div>
</div>

CSS part: CSS 部分:

@import url('https://fonts.googleapis.com/css?family=Roboto');
body {background-color: #0D1B2B; overflow-x: hidden; font-family: roboto; -webkit-font-smoothing: antialiased; margin: 0;}
.flex { display: -webkit-flex; display: flex; -webkit-flex-direction: row;  flex-direction: row; -webkit-justify-content: flex-start; justify-content: flex-start;}

.slider-wrapper div {position: relative;}
.slider-wrapper {margin-top: 5vw;  margin-left: 11vw;}
.slide-image {height: 24vw;}
.slide-image img {width: 24vw; cursor: pointer;}
.slide-content {width: 25vw; color: #fff; padding:3vw 18vw 3vw 9vw;}
.slide-date {color: #0a8acb; font-size: 1.1vw; font-weight: 400; letter-spacing: 0.1vw; padding-bottom: 1.4vw;}
.slide-title {font-size: 1.2vw; font-weight: 400; letter-spacing: 0.1vw; line-height: 1.55vw; padding-bottom: 1.8vw;}
.slide-text {font-size: 0.80vw; line-height: 1.2vw; opacity: 0.8; padding-bottom: 4vw;}
.slide-more {font-weight: 400; letter-spacing: 0.1vw; float: left; font-size: 0.9vw;}
.slide-bullet {width: 0.5vw; height: 0.5vw; background-color: #0b8bcc; border-radius: 200%; position: relative; margin-left: 1.2vw;}
.slide-nav {margin-left: 64vw; margin-top: -5.5vw;}

div.overlay-blue {width: 100%; height: 100%; position: absolute; top: 0; transition: 0.5s ease all;}
div.overlay-blue:hover {background-color: rgba(13, 27, 43, 0.5);}

.arrows{width: 3.5vw; margin-top: -5.8vw; margin-left: 72vw; position: relative;}
.arrow {display: inline-block; position: absolute; width: 1.2vw; height: 1.2vw; background: transparent; text-indent: -9999px; border-top: 0.15vw solid #fff; border-left: 0.15vw solid #fff; transition: all .1s ease-in-out; text-decoration: none; color: transparent;
}
.arrow:hover {border-color: #0A8ACB; border-width: 0.25vw;
}
.arrow:before {display: block; height: 200%; width: 200%; margin-left: -50%; margin-top: -50%; content: ""; transform: rotate(45deg);}
.arrow.prev {transform: rotate(-45deg); left: 0;}
.arrow.next {transform: rotate(135deg); right: 0;}

JS part: JS部分:

( function($) {

  $(document).ready(function() {

    var s           = $('.slider'),
        sWrapper    = s.find('.slider-wrapper'),
        sItem       = s.find('.slide'),
        btn         = s.find('.slider-link'),
        sWidth      = sItem.width(),
        sCount      = sItem.length,
        slide_date  = s.find('.slide-date'),
        slide_title = s.find('.slide-title'),
        slide_text  = s.find('.slide-text'),
        slide_more  = s.find('.slide-more'),
        slide_image = s.find('.slide-image img'),
        sTotalWidth = sCount * sWidth;

    sWrapper.css('width', sTotalWidth);
    sWrapper.css('width', sTotalWidth);

    var clickCount  = 0;

    btn.on('click', function(e) {
      e.preventDefault();

      if( $(this).hasClass('next') ) {

        ( clickCount < ( sCount - 1 ) ) ? clickCount++ : clickCount = 0;
      } else if ( $(this).hasClass('prev') ) {

        ( clickCount > 0 ) ? clickCount-- : ( clickCount = sCount - 1 );
      }
      TweenMax.to(sWrapper, 0.4, {x: '-' + ( sWidth * clickCount ) })


      //CONTENT ANIMATIONS

      var fromProperties = {autoAlpha:0, x:'-50', y:'-10'};
      var toProperties = {autoAlpha:0.8, x:'0', y:'0'};

      TweenLite.fromTo(slide_image, 1, {autoAlpha:0, y:'40'}, {autoAlpha:1, y:'0'});
      TweenLite.fromTo(slide_date, 0.4, fromProperties, toProperties);
      TweenLite.fromTo(slide_title, 0.6, fromProperties, toProperties);
      TweenLite.fromTo(slide_text, 0.8, fromProperties, toProperties);
      TweenLite.fromTo(slide_more, 1, fromProperties, toProperties);

    });

  });
})(jQuery);

$('.overlay').addClass('overlay-blue');

Many thanks.非常感谢。

Good morning,早上好,

you can console.log(sWidth, 'sWidth') under your variables declaration and see that your variable don't return the same value in different browsers.您可以在变量声明下使用 console.log(sWidth, 'sWidth') 并查看变量在不同浏览器中返回的值不同。

The solution:解决方案:

remove flex class from your slide html code and change the display to block to get the same calculation cross browsers and you should add another div inside it to keep your flex style.从幻灯片 html 代码中删除 flex class 并将显示更改为阻止以获得相同的跨浏览器计算,并且您应该在其中添加另一个 div 以保持您的 flex 样式。

change your HTML slide code to:将您的 HTML 幻灯片代码更改为:

 <div class="slide">
      <div class="slide-container">
      <div class="slide-image slider-link prev"><img src="https://goranvrban.com/codepen/img2.jpg">
              <div class="overlay"></div>
            </div>
            <div class="slide-content">
               <div class="slide-content-inner">
              <div class="slide-date">30.07.2017.</div>
              <div class="slide-title">LOREM IPSUM DOLOR SITE MATE, AD EST ABHORREANT</div>
              <div class="slide-text">Lorem ipsum dolor sit amet, ad est abhorreant efficiantur, vero oporteat apeirian in
                vel. Et appareat electram appellantur est. Ei nec duis invenire. Cu mel ipsum laoreet, per rebum omittam ex.
              </div>
          <div class="slide-more">READ MORE</div>
        </div>
     </div>
  </div>
</div>

and add these css styles:并添加这些 css styles:

.slide {
  display:block;
}

.slide-container{
  display: flex;
}
.slide-content-inner{
  width:35vw;
  padding: 5%;
}

And change these (remove the padding and change width):并更改这些(删除填充并更改宽度):

.slide-content {
   width: 50vw;  //changed to 50vw
   color: #fff; 
   /*padding:3vw 18vw 3vw 9vw;*/ //removed
}

You get the solution with extra styling:)您将获得额外样式的解决方案:)

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

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