在悬停

时间:2015-04-22 11:05:47

标签: javascript jquery html5 css3

当我正在徘徊时,我正试图在我的链接的严谨侧显示一个bootstrap glyphicon。

我尝试过使用CSS和JS,但它不会工作。所以我需要帮助:)

这就是我要做的事:When i hoover FooI want the pencil icon to show。等等。当我胡扯'Bar'和'这是一个链接'时也会发生同样的事情

我也希望它成为一个按钮。

这就是html的样子:

<div class="nesting">
  <a href="#" class="nesting-item"><span class="glyphicon glyphicon-folder-open" area-hidden="true"></span> Foo <div class="pull-right"><span class="glyphicon glyphicon-pencil" area-hidden="true"></div></a>
  <div class="nesting_child">
    <a href="#" class="nesting-item"><span class="glyphicon glyphicon-chevron-right" area-hidden="true"></span> Bar</a>
    <a href="#" class="nesting-item"><span class="glyphicon glyphicon-globe" area-hidden="true"></span> This is a link</a>

感谢您的帮助:)

2 个答案:

答案 0 :(得分:1)

添加&#34;隐藏&#34; class和你的铅笔div的id和你的id&#34; Foo&#34;锚:

<a href="#" class="nesting-item" id="foo">
    <span class="glyphicon glyphicon-folder-open" area-hidden="true"></span> Foo 
    <div id="pencil-glyph" class="pull-right hidden">
        <span class="glyphicon glyphicon-pencil" area-hidden="true"></span>
    </div>
</a>

CSS:

.hidden { display: none; }

然后向你的锚添加一个悬停事件监听器(例如使用jQuery),它添加/删除隐藏的类(https://api.jquery.com/hover/):

$('#foo').hover(function () {
    $('#pencil-glyph').removeClass('hidden'); 
}, function () {
    $('#pencil-glyph').addClass('hidden');
});

答案 1 :(得分:1)

您可以使用div的背景颜色作为glyphicon的颜色,并且在将div / glyphicon悬停时可以启用glyphicon。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
button{
 font-size: 30px;
                background: white;
                border: 2px solid blue;
                margin-top: 10px;
                border-radius: 2px;
                box-sizing: border-box;
                color: blue;
                cursor: pointer;
                padding: 10px 24px;
                transition: box-shadow 200ms;
				
				
            } 
button:hover{
                font-size: 30px;
                background:blue;
                border: 0;                
                border-radius: 2px;
                box-sizing: border-box;
                color: #fff;
                cursor: pointer;
                padding: 10px 24px;
                transition: box-shadow 200ms;
                
            }  
			span{
			color:white;
}
span:hover {    
}
</style>
<body>

<div class="container">
     <button type="button">
        text<span class="glyphicon glyphicon-ok" ></span>
    </button>
  <button type="button">
        text1<span class="glyphicon glyphicon-ok" ></span>
    </button>
	<button type="button">
        text2<span class="glyphicon glyphicon-ok" ></span>
    </button>
</div>

</body>
</html>