简体   繁体   English

CSS/JS 效果在 Safari 上损坏

[英]CSS/JS effects broken on Safari

Ive added CSS animations on text that are triggered by JS, they work fine in all browsers apart from Safari.我已经在 JS 触发的文本上添加了 CSS 动画,它们在除 Safari 之外的所有浏览器中都能正常工作。 When you click a line of text all lines of text fade out, on Safari, once you've clicked the text and go to the next page, if you click back the effect is triggered on page load and then resets and wont trigger on click.当您单击一行文本时,所有文本行都会淡出,在 Safari 上,一旦您单击文本和 go 到下一页,如果单击返回,效果会在页面加载时触发,然后重置并且不会在单击时触发.

Any idea how to fix this for Safari, you can see the effect on this page知道如何为 Safari 解决此问题,您可以在此页面上看到效果

This is the CSS animation:这是 CSS animation:

.hometext.active {

  animation: fadeOutBottomLeft; /* referring directly to the animation's @keyframe declaration */
  animation-duration: 2s;
}

.hometext.slide {

  animation: fadeOutTopRight; /* referring directly to the animation's @keyframe declaration */
  animation-duration: 2s;
}

This is the code im using to trigger the effects:这是我用来触发效果的代码:

  jQuery(".hometext").click(function() {
    jQuery(this).toggleClass("slide");
    jQuery(".hometext").toggleClass("active");
        jQuery("#header-elementor").toggleClass("active");
  })
})

Browser backbutton jQuery script.浏览器后退按钮jQuery脚本。

$(window).on('popstate', function(event) {
 alert("pop");
 // Write your code here when user click the browser back button.
});

After your comments if I understand correctly you want opposite animation on Browser backbutton when user clicked it.在您发表评论后,如果我理解正确,您希望在用户单击浏览器后退按钮时与animation相对。 Simply it will not work for you.只是它对你不起作用。 You have to understand how browser Back Button work.您必须了解浏览器后退按钮的工作原理。

window.history.replaceState(); //work exactly like pushstate bt this one replace the history instead of creating new one...
window.history.backward(); // To move backward through history, just fire this event...
window.history.forward();// To move forward through history ...
window.history.go(-1); // Go back to one page(or whatever value u passed) through history
window.history.go(1); // Go forward to one page through history..

I tested your site in MacOS 10.14 Mojave and Safari Version 13.1.1 It will work same like as chrome.我在MacOS 10.14 MojaveSafari版本13.1.1中测试了您的站点,它的工作方式与 chrome 相同。

You could try:你可以试试:

jQuery(".hometext").click(function(e) {
  jQuery(this).toggleClass("slide");
  jQuery(".hometext").toggleClass("active");
      jQuery("#header-elementor").toggleClass("active");
  setTimeout(()=> { 
    //remove the classes so they don't get reactived with back button
    //since you mentioned page load time is what's causing the delay, you may have to skip this
    jQuery(this).toggleClass("slide");
    jQuery(".hometext").toggleClass("active");
        jQuery("#header-elementor").toggleClass("active");
    //store the link in a custom attribute or any attribute and force redirect
   window.location.href = e.target.getAttribute('data-link');
    //set timeout to after animation
  },2000)
})

You would also have to strip your anchor tags of any href;您还必须剥离任何 href 的锚标记; unfortunately Safari is a very fickle browser when it comes to CSS.不幸的是,Safari 在 CSS 方面是一个非常善变的浏览器。

Edit: Example html编辑:示例 html

<div data-link="/portfolio/elijah" class="elementor-element elementor-element-da798b1 hometext elementor-widget elementor-widget-heading" data-id="da798b1" data-element_type="widget" data-widget_type="heading.default">
    <div class="elementor-widget-container">
      < h2 class="elementor-heading-title elementor-size-default">
        <a href="">DRUM&amp;BASSARENA</a>
      </h2>     
    </div>
</div>

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

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