简体   繁体   English

将鼠标悬停在链接上

[英]Slide in link on hover over

I want to create the following action: 我要创建以下操作:

When you move your mouse over a piece of text in a navigation bar fixed on the left hand side of the screen, a second piece of text (or an image if that is easier), will appear by sliding out from the left of the page. 当您将鼠标移到屏幕左侧固定的导航栏中的一段文本上时,将从页面左侧滑出会显示第二段文本(或图像,如果这样更容易)。 。 The second text or image would rest under the first (possible offset for effect). 第二个文本或图像将位于第一个文本或图像的下方(可能会产生偏移)。 On mouseoff the above effect would reverse and you would be left with only the first piece of text. 在mouseoff上,上述效果将反转,您将只剩下第一段文字。

I hope that makes sense, i have been trawling transition and hover over effects on the web, but I can't quite find what I have envisioned. 我希望这是有道理的,我一直在拖延过渡并将鼠标悬停在Web上的效果上,但是我不太能找到我所设想的。

Here's a little something I knocked together for you as an example. 作为示例,我为您提供了一些帮助。 It uses jQuery : 它使用jQuery

The HTML : HTML

<div class="text">
    <a>Text One</a>
    <a>Text Two</a>
</div>

The CSS : CSS

.text{
    width:200px;
    position:relative;
}

.text > a{

    position:relative;
    left:-100%;
    display:none;

}

.text > a:first-child{

  left:0;
  display:block;

}

The JavaScript : JavaScript

$(document).ready(function(){ // here we're only running the code when the page is ready

    $('.text > a:first-child').hover(function(){ // here we're targeting the first .text element

      $(this).siblings().css('display', 'block'); // we're making it visible
      $(this).siblings().animate({'left':'0%'}); // we're animating it out of it's hidden state

    }, function(){ // this function is passed as the second argument to the 'hover' method

      $(this).siblings().animate({'left':'-100%'}, 500, function(){ // animate back to hidden state

        $(this).css('display', 'none'); // when the animation is complete, hide it completely

    });
  });
});

Here's a working example on jsFiddle. 这是jsFiddle上的一个工作示例

Obviously the concept could be optimised/developed... 显然,这个概念可以被优化/发展。

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

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