使用Jquery的标签

时间:2019-02-18 20:55:15

标签: jquery html css

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

我希望在单击任何选项卡时,请参考所单击的选项卡来更改选项卡下方的内容。

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

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

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

有道理吗?预先非常感谢

1 个答案:

答案 0 :(得分: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>