简体   繁体   English

将鼠标悬停在不同链接上时如何更改菜单图像?

[英]How to change menu image when hovering over different links?

Let me start of by saying that I am new to this.首先让我说我是新手。 I have some code from a template that I am using.我有一些来自我正在使用的模板的代码。 On the menu drop down there is a list of the links to other pages and next to it is an image.在下拉菜单上有一个指向其他页面的链接列表,旁边是一个图像。 What would I need to add to make the image change to another image when you hover over each of the links?当您将鼠标悬停在每个链接上时,我需要添加什么才能将图像更改为另一个图像?

Here is the code.这是代码。

<li class="menu-item-has-children megamenu">
    <a href="#">
        <span class="link-icon"></span>
        <span class="link-txt">
            <span class="link-ext"></span>
            <span class="txt">
                Equipment
                <span class="submenu-expander">
                    <i class="fa fa-angle-down"></i>
                </span>
            </span>
        </span>
    </a>
    <ul class="nav-item-children">
        <li>
            <div class="container megamenu-container">
                <div class="vc_row row megamenu-inner-row bg-white p-0">
                    <div class="container ld-container">
                        <div class="row ld-row">

                            <div class="megamenu-column col-md-3 py-md-3 px-md-4">
                                <div class="megamenu-column-inner pl-md-4 py-md-4">
                                    <ul class="lqd-custom-menu reset-ul font-size-15 lh-2 ltr-sp-025 font-weight-medium">
                                        <li>
                                            <a href="#"><i class="fa fa-angle-right mr-2"></i>Vertical Cartoners</a>
                                        </li>
                                        <li>
                                            <a href="#"><i class="fa fa-angle-right mr-2"></i>Horizontal Cartoners</a>
                                        </li>
                                        <li>
                                            <a href="#"><i class="fa fa-angle-right mr-2"></i>Pre Made Pouch Machines</a>
                                        </li>
                                        <li>
                                            <a href="#"><i class="fa fa-angle-right mr-2"></i>Case Packers</a>
                                        </li>
                                        <li>
                                            <a href="#"><i class="fa fa-angle-right mr-2"></i>Rigid Container Fillers</a>
                                        </li>
                                        <li>
                                            <a href="#"><i class="fa fa-angle-right mr-2"></i>Carton Sleeve Wrappers</a>
                                        </li>
                                    </ul>
                                </div><!-- /.megamenu-column-inner -->
                            </div><!-- /.megamenu-column -->

                            <div class="megamenu-column col-md-3 bg-cover bg-center" data-responsive-bg="true">
                                <img class="invisible" src="./img/equipment/vertical-cartoner.jpg" alt="Megamenu Image">
                            </div><!-- /.megamenu-column -->


                        </div><!-- /.row ld-row -->
                    </div><!-- /.container ld-container -->
                </div><!-- /.vc_row -->
            </div><!-- /.megamenu-container -->
        </li>
    </ul>
</li>

Find this in your css stylesheet在你的 css 样式表中找到这个

.megamenu .link-icon {
  ...
}

Add the next lines right after it for a mouse-over effect.在它之后添加下一行以获得鼠标悬停效果。 Sorry for the dots.对不起点。 For reason that your current css is unknown it is not possible to give the full solution.由于您当前的 css 未知,因此无法提供完整的解决方案。

.megamenu > a:hover .link-icon {
  ...
}

I would use scripting for this kind of thing我会为这种事情使用脚本

 $(document).ready(function(){ $('#op1').hover(function(){ $('#image').css('background-image','url("https://via.placeholder.com/150.png?text=op1")') }); $('#op2').hover(function(){ $('#image').css('background-image','url("https://via.placeholder.com/150.png?text=op2")') }); $('#op3').hover(function(){ $('#image').css('background-image','url("https://via.placeholder.com/150.png?text=op3")') }); });
 #image{ background-image: url("https://via.placeholder.com/150"); border: 1px solid black; width: 150px; height: 150px; } #op1, #op2, #op3{ padding: 5px; cursor: pointer; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="image"></div> <div id="op1">hover for op1</div> <div id="op2">hover for op2</div> <div id="op3">hover for op3</div>

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

相关问题 将鼠标悬停在图片上时更改文字,文字与图片的位置不同 - Change Text when hovering over image, text is in a different location then image 将鼠标悬停在图像上时如何更改div的backgroundImage和innerHTML? - How to change the backgroundImage and innerHTML of a div when hovering over an image? 将鼠标悬停在图像上时如何更改 SVG 的颜色? - How to change the color of the SVG when hovering over the image? 将鼠标悬停在链接上时如何更改图像? - How can I change the image when hovering over a link? 下拉菜单将鼠标悬停在上方时将其他链接向下推 - drop down menu pushing other links down when hovering over 将鼠标悬停在上方时更改图像颜色 - Change image color when hovering over li 将鼠标悬停在文本列表上时更改图像 - Change image when hovering over a list of text 如何通过将鼠标悬停在不同容器中的元素/链接上来更改一个容器的内容 - How to change the contents of one container by hovering over elements/links in a DIFFERENT container 将鼠标悬停在特定的导航链接上时,如何交换具有不同徽标的页面徽标 - How Do I Swap Page Logo With Different Logo When Hovering Over Specific Nav Links 在 Bootstrap 中,当鼠标悬停在导航栏中时,如何更改链接的颜色? - In Bootstrap, how do I change what color the links are in my navbar when hovering over them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM