【问题标题】:vertical navigation on hover change image悬停更改图像上的垂直导航
【发布时间】:2017-11-27 11:39:27
【问题描述】:

我正在努力寻找一个简单的解决方案来创建这样的 div 导航: https://www.bueromoebel-experte.de/

当鼠标悬停在左侧菜单时,右侧带有图像的 div 会发生变化(并保留 div,即使您用鼠标移动到其他地方也是如此)。但是左侧菜单本身,当它被点击时链接到另一个页面。

一定是这样的:

<ul>
<li> <a id="link1" href="example.de/abc" target="_blank">example 1</a></li>
<li> <a id="link2" href="example.de/def" target="_blank">example 2</a></li>
<li> <a id="link3" href="example.de/ghi" target="_blank">example 3</a></li>
</ul>

<div id="example1" class="hide"> Image, Text and Button</div>
<div id="example2" class="hide"> Image, Text and Button</div>
<div id="example3" class="hide"> Image, Text and Button</div>

CSS

.hide {
  position: absolute;
}
#example1 {
   z-index: 50;
}
#example3, #example2 {
   z-index: 10;
}

JS

$("HOVEREDLINK").hover(function() {
  $("HOVEREDLINK").css("z-index","70")
  $("ALLOTHERIDS").css("z-index","50")
});

作为一个初学者,我不太确定该怎么做,或者这是否是一个好的解决方案。如果你们能帮助我,我将非常感激。非常感谢!

【问题讨论】:

  • 如果您可以为您的案例创建代码 sn-p 或工作示例,它将帮助您和其他寻求帮助的成员

标签: javascript jquery css slider


【解决方案1】:

试试这样的

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";
}
* {box-sizing: border-box}
body {font-family: "Lato", sans-serif;}

/* Style the tab */
div.tab {
    float: left;
    border: 1px solid #ccc;
    background-color: #f1f1f1;
    width: 30%;
    height: 300px;
}

/* Style the buttons inside the tab */
div.tab button {
    display: block;
    background-color: inherit;
    color: black;
    padding: 22px 16px;
    width: 100%;
    border: none;
    outline: none;
    text-align: left;
    cursor: pointer;
    transition: 0.3s;
    font-size: 17px;
}

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

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

/* Style the tab content */
.tabcontent {
    float: left;
    padding: 0px 12px;
    border: 1px solid #ccc;
    width: 70%;
    border-left: none;
    height: 300px;
}
<!DOCTYPE html>
<html>
<body>
<div class="tab">
  <button class="tablinks" onmouseover="openCity(event, 'London')" id="defaultOpen">London</button>
  <button class="tablinks" onmouseover="openCity(event, 'Paris')">Paris</button>
  <button class="tablinks" onmouseover="openCity(event, 'Tokyo')">Tokyo</button>
</div>

<div id="London" class="tabcontent">
  <h3>London</h3>
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
</div>

<script>
document.getElementById("defaultOpen").onmouseover();
</script>
     
</body>
</html> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    相关资源
    最近更新 更多