简体   繁体   English

为什么我的 CSS 转换在通过 jQuery 添加类时不起作用?

[英]Why are my CSS transitions not working when adding classes through jQuery?

I'm making a website and the transition is not working how it's suppose to.我正在制作一个网站,但转换没有按预期进行。 also, 7.css doesn't interfere because it's the same issue without it and also the transition works when using window:hover.此外,7.css 不会干扰,因为没有它也是同样的问题,而且在使用 window:hover 时过渡也有效。

I tried to add a class through jQuery, and what should happen is it should apply the css transition on the window class.我试图通过 jQuery 添加一个类,应该发生的是它应该在窗口类上应用 css 转换。 however, it does not work and adds the class but does not do the transition.但是,它不起作用并添加了类但不进行转换。

HTML: HTML:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <link rel="stylesheet" href="https://unpkg.com/7.css">
  </head>
  <body>
    <div class="vertical"></div>
    <div id=info1>
    <div class="window active glass center400" style="max-width:400px;">
      <div class="title-bar">
        <div class="title-bar-text">Info</div>
        <div class="title-bar-controls">
          <button aria-label="Minimize" disabled></button>
          <button aria-label="Maximize" disabled></button>
          <button aria-label="Close" class=closewindow data-parentid=info1 onclick=closeinfo()></button>
        </div>
      </div>
      <div class="window-body has-space">
        <h4>donkeys are pretty cool</h4><br><br>
        i love donkeys.
      </div>
    </div>
    </div>
  </body>
</html>

CSS: CSS:

    body {
      margin: 0;
      padding: 0;
      background: url(img0.jpg) center center fixed;
      overflow: hidden;
    }
      .window {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        transform: perspective(0), rotateZ(0);
        opacity: 1;
        -webkit-transition: 200ms ease all, 300ms ease opacity;
        -moz-transition: 200ms ease all, 300ms ease opacity;
        -ms-transition: 200ms ease all, 300ms ease opacity;
        transition: 200ms ease all, 300ms ease opacity;
      }
      .window-body {
        -webkit-user-select: default;
        -ms-user-select: default;
        user-select: default;
      }
      div.vertical {
        display: none;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
        z-index: 1000 !important;
        background: red;
      }
      
      @media only screen and (max-aspect-ratio: 6/5) {
        div.vertical {
          display: block;
        }
      }
      h4 {
        padding: 0;
        margin: 0;
      }
      .center400 {
        left: calc(50vw - 200px);
        top: 35vh;
      }
      [role=button],button{
          transition: 100ms;
      }
      .close {
        transform-style: preserve-3d;
        transform: perspective(1500px) rotateX(10deg) translateY(-10px);
        opacity: 0;
      }

jQuery:查询:

     function closeinfo() {
        $("#info1").addClass("close");
      }
      $(".window").draggable({
        handle: ".title-bar"
      });

fiddle: fiddle小提琴:小提琴

I figured it out, i just needed to get rid of the wrapper div and put #info on the window div.我想通了,我只需要摆脱包装 div 并将 #info 放在窗口 div 上。

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

相关问题 通过添加和删除类的CSS过渡 - CSS transitions by adding and removing classes 使用javascript / jQuery添加类时,为什么css过渡不起作用? - Why is css transition not working when adding class using javascript / jQuery? 为什么我的 barbajs 转换在与 parcel 捆绑在一起时停止工作? - Why does my barbajs transitions stop working when bundled with parcel? 反应切换类+ CSS转换,不工作......为什么? - React toggle class + CSS transitions, not working… why? 为什么我的 css 类在我的 React 项目中不起作用? - Why are my css classes not working in my React project? 为什么[my] CSS3 / jQuery转换得如此不完美,如何使它们更加流畅? - Why are [my] CSS3/jQuery transitions so imperfectly smooth, and how do I make them more smooth? 使用 jquery 添加和删除 CSS 类 - Adding and removing CSS classes with jquery 为什么我的jQuery UI CSS无法在JSFiddle中运行? - Why is my jQuery UI CSS not working in JSFiddle? 为什么我的jQuery .css函数不起作用? - Why is my jQuery .css function not working? 为什么通过带有gmap事件点击监听器的jQuery将自定义类添加到主体时,为什么我的自定义类未应用于主体? - Why my custom class is not applied to body when adding it through jQuery with gmap event click listener?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM