简体   繁体   English

如何使 javascript 旋转木马的过滤器正常工作

[英]how make filter for javascript carousel functional

JavaScript carousel for work section which should display all my work by default in "All Work" but when a user clicks on App work only app work should display and when a user clicks on web work only web work should display. JavaScript 工作部分的轮播,默认情况下应在“所有工作”中显示我的所有工作,但是当用户单击应用程序工作时,仅应显示应用程序工作,当用户单击web工作时,应仅显示 Z2567A5EC9705EB7AC2DZ9848 工作。

The filter property of "All Work" , "App Work" , "Web Work" is not functional and I have no idea how to make that work. "All Work""App Work""Web Work"的过滤器属性不起作用,我不知道如何使其工作。

check how its look on the website view link检查它在网站查看链接上的外观

source file GitHub Link源文件GitHub 链接

GitHub issues Link GitHub 问题链接

Buttons are not doing anything.按钮没有做任何事情。

I need that when "All Work" get click both slides appear one after other in sequence "App Work" then "Web Work" .我需要当“所有工作”得到点击时,两张幻灯片依次出现在“App Work”然后是“Web Work” and when "App Work" gets click all carousel slides of "App Work" will appear one after other in sequence.“App Work”被点击时,“App Work 的所有轮播幻灯片将依次出现。 and when "Web Work" gets click all carousel slides of "Web Work" will appear one after other in sequence.“Web Work”被点击时,“Web Work 的所有轮播幻灯片将依次出现。 like a filter.像一个过滤器。

what I have tried我试过的

but not get the desired result但没有得到想要的结果

  1. Adding css style .hide { display: none; }添加 css 样式 .hide .hide { display: none; } .hide { display: none; } with the above method, the size of the slides remains there. .hide { display: none; }使用上述方法,幻灯片的大小仍然存在。

  2. Adding innerHTML for Web Work buttonWeb 工作按钮添加 innerHTML

const myworkBuild = document.querySelector(".mywork");
webWork.addEventListener("click", () => {
myworkBuild.innerHTML = "";
  for (let i = 0; i < 3; i++) {
    myworkBuild.innerHTML +=
      '<div class="slide web"><div class="webWork"><div class="webSS">' +
      '<img src="dell.png" />' +
      '</div><div class="webContent">' +
      "<h2>>Web 2 slide</h2>" +
      "<p>Lorem ipsum Fugit eius nemo</p>" +
      '<div class="button">' +
      '<a href="#">Get Apk</a>' +
      '<a href="#">More Info</a>' +
      "</div></div></div></div>";
  }
});
  1. Adding innerHTML with Array for App Work button使用 Array for App Work按钮添加 innerHTML
const myworkBuild = document.querySelector(".mywork");
appWork.addEventListener("click", () => {
const appData = [
    [
      "WhatsApp-UI-Clone",
      "whatsapp3.gif",
      "Just simple UI clone of WhatsApp, This app is built with flutter.",
      "#getapplink",
      "https://github.com/shahbajjamil",
    ],
    [
      "WhatsApp-UI-2",
      "whatsapp3.gif",
      "Just simple UI clone of WhatsApp, This app is build with flutter.",
      "#getapplink",
      "https://github.com/shahbajjamil",
    ],
  ];

  myworkBuild.innerHTML = "";
  for (let i = 0; i < appData.length; i++) {
    myworkBuild.innerHTML +=
      '<div class="slide app"><div class="appWork"><div class="appSS">' +
      '<img src='+appData[i][1]+' />' +
      '</div><div class="appContent">' +
      "<h2>"+appData[i][0]+"</h2>" +
      "<p>"+appData[i][2]+"</p>" +
      '<div class="button">' +
      '<a href='+appData[i][3]+'>Get Apk</a>' +
      '<a href='+appData[i][4]+'>More Info</a>' +
      "</div></div></div></div>";
  }
});

with the above method let slides = document.querySelectorAll(".slide");使用上述方法let slides = document.querySelectorAll(".slide"); does not update, so the slides.NodeLists.length remain the same even though slide get change, which leads to the same number of carousel slides in all filters "All Work" , "App Work" , "Web Work" when slides are less in number any section it displays empty carousel slide and when slides are more in any section it gets omit form carousel slide.不会更新,因此即使幻灯片发生更改, slides.NodeLists.length仍保持不变,这会导致幻灯片较少时所有过滤器"All Work""App Work""Web Work"中的轮播幻灯片数量相同在任何部分的数量中,它都会显示空的轮播幻灯片,当任何部分的幻灯片更多时,它会省略形式的轮播幻灯片。

check how its look on the website view link检查它在网站查看链接上的外观

source file GitHub Link源文件GitHub 链接

GitHub issues Link GitHub 问题链接

HTML code for App Work应用程序工作的 HTML 代码

          <div class="slide app">
             <div class="appWork">
                <div class="appSS">
                  <img src="whatsapp3.gif" />
                </div>
                <div class="appContent">
                  <h2>App 2 slide</h2>
                  <p>
                    Lorem ipsum Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quidem, delectus. 
                  </p>
                  <div class="button">
                    <a href="#">Get Apk</a>
                    <a href="#">More Info</a>
                  </div>
                </div>
              </div>
            </div>

HTML code for Web Work HTML 代码为Web 工作

          <div class="slide web">
              <div class="webWork">
                <div class="webSS">
                  <img src="dell.png" />
                </div>
                <div class="webContent">
                  <h2>Web 2 slide</h2>
                  <p>
                    Lorem ipsum Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quidem, delectus.
                    </p>
                  <div class="button">
                    <a href="#">View Site</a>
                    <a href="#">More Info</a>
                  </div>
                </div>
              </div>
            </div>

Please help me to fix this problem.请帮我解决这个问题。

You could add visible and hidden classes for the visible ones and hidden ones respectively.您可以分别为可见类和隐藏类添加可见类和隐藏类。 Then you can query using slides.visible.然后您可以使用 slides.visible 进行查询。

 document.querySelectorAll(".slide.visible")
 .visible { display: block }.hidden { display: none }

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

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