悬停变换图像上的垂直导航

时间:2017-11-27 11:39:27

标签: javascript jquery css slider

我很难找到一个简单的解决方案来创建这样的div-navigation: https://www.bueromoebel-experte.de/ enter image description here

右侧图像的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")
});

作为一个初学者,我不太清楚如何做或者它是一个很好的解决方案。如果你们能帮助我,我真的很感激。非常感谢你!

1 个答案:

答案 0 :(得分:1)

尝试这样的事情

&#13;
&#13;
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";
}
&#13;
* {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;
}
&#13;
<!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> 
&#13;
&#13;
&#13;