【问题标题】:show hide content on mouseover boxes在鼠标悬停框上显示隐藏内容
【发布时间】:2015-09-29 10:06:26
【问题描述】:

请有人帮忙,看起来像一个简单的功能,但对于我的生活,我无法做到正确。我需要将它插入到我的 wordpress 网站上。

当鼠标悬停在另一个块上时,它是一个简单的显示隐藏内容。与this site 上的完全一样,在标题解决方案下。我将鼠标悬停在标题栏上,我看到右侧的内容。

有没有一个非常简单的方法呢?甚至是 WP 插件?

提前致谢。

【问题讨论】:

  • 不,您只需为框创建 HTML、CSS,而不是为包含所需内容的更多 DIV 创建一个 DIV > 如果您愿意,您可以使用 jQuery 或纯 JS 显示相应的文本。
  • 你想创建那个下拉菜单吗?
  • 阿利斯特...看到这个jsbin.com/xehefu/1/edit?html,css,js,output
  • 谢谢罗科!看起来你已经搞定了。非常感谢。

标签: javascript jquery html css wordpress


【解决方案1】:

我刚刚创建了一个简单的解决方案。请在下方查看此内容或https://jsfiddle.net/oneness/Lotaaxdh/

JS/CSS/HTML 分别

                   
$( ".science" ).mouseover(function() {
  $( "#social_display" ).hide("fast"); 
  $( "#science_display" ).show("slow");
});

$( ".social" ).mouseover(function() {
  $( "#science_display" ).hide("fast");
  $( "#social_display" ).show("slow");
});
.box{
    background-color: #37545c;
    border:1px solid #000000;
    padding:5px 5px 5px 5px;
    color:#ffffff;
}
.right{
    float:right;
}
.left{
    float:left;
}
#science_display, #social_display {
    display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class='left'>
<div class="box science">Science</div><br>
<div class="box social">Social</div>
</div>

<div class='right'>
<div id='science_display'>This is the story behind Science</div>
<div id='social_display'>Social button story and other details </div>
</div>

【讨论】:

  • 这不是使用 jQuery 的方式,编程应该很有趣,而不是复制粘贴结束编辑的噩梦。保持干燥(不要重复自己)。创建一个函数并坚持下去。
  • 另外,在您的示例中,在多个元素上更快的鼠标移动将创建动画构建。
【解决方案2】:

这是我为您制作的,但如果您没有编码知识,可能很难单独添加。

https://jsfiddle.net/Skaadel/5s7symfe/

jQuery

$('#puppies').hover(function() {
  $('.display').html('Puppies'); /** Change ('Puppies') to change text displayed when hover**/
});

$('#kittens').hover(function() {
  $('.display').html('Kittens');/** Change ('Kittens') to change text displayed when hover**/
});

$('#aardvark').hover(function() {
  $('.display').html('Aardvark'); 
/** Change ('Aardvark') to change text displayed when hover**/
});

HTML

<div class="container"> 
  <div id ="kittens"></div>
  <div id ="aardvark"></div>
  <div id ="puppies"></div>
</div>
<br>

<div class="display">Hover on the picture for description.</div>

CSS

    body { background: black; }

.display {
  font:20pt 'Georgia';
  height:50px;
  width: 759px;
  text-align:center;
  background-color: white;
  border: 1px solid black;
  margin: auto;
}
.container{
height: 250px;
width: 759px;
margin: auto;
border: 3px solid black;
}

#kittens{
  background-image: url(http://goo.gl/Ktu3u0);
  height: 250px;
  width: 250px;
  display: inline-block;
}
#aardvark{
  background-image: url(http://goo.gl/qQUUff);
  height: 250px;
  width: 250px;
  display: inline-block;
}
#puppies{
  background-image: url(http://goo.gl/6gvDn2);
  height: 250px;
  width: 250px;
  display: inline-block;
}

我做的很快,所以设计不是那么漂亮。

【讨论】:

  • 使用类而不是创建 8 个(或更多)单独的函数
  • 啊!我对使用 Jquery 和 JS 还是很陌生。你介意告诉我最好的设置方法吗?如果您有时间更改 Jsfiddle 以便我看到它,我将不胜感激。
  • 查看我在原始海报的 cmets 部分发布的演示
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 1970-01-01
  • 2011-10-01
相关资源
最近更新 更多