带有Jquery的选项卡[关闭]

问题描述 投票:-5回答:1

我在这个页面上工作:https://www.landingpagedude.ca/max-ahg/我有3个标签(产品演示,专家聊天会话和最佳虚拟现实!),如图所示:https://prnt.sc/mmvin2

我希望在点击任何标签时,更改标签下方的内容,参考点击的标签。

这个内容https://prnt.sc/mmvjsn指的是第一个标签:

其他2可以是任何随机内容。唯一的细节是选定的选项卡必须处于活动状态,将鼠标悬停在选项卡上时具有相同的样式(悬停)

这是移动视图:https://prnt.sc/mmvmi1

说得通?非常感谢你提前

jquery html css
1个回答
1
投票

这是从w3schools我刚刚编辑到你正在尝试完成的。我建议你在这个主题上做一些研究,看看什么最适合你,因为像Boostrap这样的框架可能有所帮助。

function openCity(evt, cityName) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
/* Style the tab */
.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
.tab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
}

/* Change background color of buttons on hover */
.tab button:hover {
  background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
  background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
}
<h2>Tabs</h2>
<p>Click on images and the contect will apper at the Buttom of it</p>

<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')"><img width="50mm" src="https://images.discordapp.net/avatars/485508882475778058/c03979b0f78a5a5ec2badca1f1520f14.png?size=512"></button>
  <button class="tablinks" onclick="openCity(event, 'Paris')"><img width="100mm" src="https://singularityhub.com/wp-content/uploads/2018/10/man-into-virtual-reality-world_shutterstock_519713428-1068x601.jpg"></button>
  <button class="tablinks" onclick="openCity(event, 'Tokyo')"><img width="100mm" src="http://www.chutingstar.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/a/e/aerodyne_pilot_1.jpg"></button>
</div>

<div id="London" class="tabcontent">
  Choose from NSW, VIC or QLD product demonstrations and let us take you on the ultimate product journey.
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
  <p>Paris is the capital of France.</p> 
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.