简体   繁体   English

使链接悬停与href具有相同的效果?

[英]Give link hover same effect as href?

Is there any way to make hovering over a navigation anchor link act similarly to a href action, where hovering the link for an 'About' link (like in my site below) displays goes directly to the 'About' section of the page, and then moving the mouse away from the link goes back to the original div if the 'About' link is not clicked on? 是否有任何方法可以使悬停在导航锚链接上的行为类似于href动作,将鼠标悬停在“关于”链接的链接(如下面的我的站点中)显示直接转到页面的“关于”部分,并且那么如果未单击“关于”链接,则将鼠标从链接移开会返回到原始div?

Codepen: http://codepen.io/anon/pen/zZdzmB . Codepen: http ://codepen.io/anon/pen/zZdzmB。

HTML: HTML:

<nav>

    <ul id="menu">

        <li>

            <a>Menu</a>

             <div id="dropdown">

            <ul>

                <li class="navLink active"><a href="#homeSection"><div class="navLine"></div>Home</a></li>

                <li class="navLink"><a href="#aboutSection"><div class="navLine"></div>About</a></li>

                <li class="navLink"><a href="#skillsSection"><div class="navLine"></div>Skills</a></li>

                <li class="navLink"><a href="#workSection"><div class="navLine"></div>Work</a></li>

                <li class="navLink"><a href="#contactSection"><div class="navLine"></div>Contact</a></li>

            </ul>

            </div>

        </li>

    </ul>

    </nav>

    <main>

        <section id="homeSection" class="section" data-anchor="home">

            <div class="sectionContent">

                <h1 id="intro">Intro text</h1>

            </div>

        </section>

        <section id="aboutSection" class="section" data-anchor="about">

            <div class="sectionContent">



            </div>

        </section>

        <section id="skillsSection" class="section" data-anchor="skills">

            <div class="sectionContent">



            </div>

        </section>

        <section id="workSection" class="section" data-anchor="work">

            <div class="sectionContent">



            </div>

        </section>

        <section id="contactSection" class="section" data-anchor="contact">

            <div class="sectionContent">



            </div>

        </section>

    </main>

you could use jQuery 你可以使用jQuery

$('.navLink').hover(function(){  
    $(this).trigger('click');  
}); 

You can just use the .mouseover() function. 您可以只使用.mouseover()函数。

I updated your CodePen with these change: http://codepen.io/anon/pen/vxJWVp 我通过以下更改更新了CodePen: http ://codepen.io/anon/pen/vxJWVp

Here's the Jquery Mouseover function: 这是Jquery Mouseover函数:

$( document ).ready(function() {
 $('#1').mouseover(); 
});

$('#1').mouseover(function() {
$('#intro').html('Intro');

});

$('#2').mouseover(function() {
$('#intro').html('About Content goes here');

});

$('#3').mouseover(function() {
 $('#intro').html('Skills Content goes here');

 });

 $('#4').mouseover(function() {
 $('#intro').html('Work Content goes here');

 });

 $('#5').mouseover(function() {
   $('#intro').html('Contact Content goes here');

 });

Then just add the respective ' id = "1" ' 然后只需添加相应的'id =“ 1”'

<li class="navLink active" id="1"><a href="#homeSection">
<div class="navLine"></div>Home</a></li>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM