在另一个

时间:2016-05-12 14:28:07

标签: javascript jquery html css

我试图将鼠标悬停在包装器内的div上,以便在另一个说唱歌手中显示一些文字。

我用以下的CSS刺伤了它,但无济于事。这是我到目前为止的尝试:

Fiddle

这是我尝试用CSS做的事情:

 /* My attempt */
 #assotxt {
   display: none;
 }

 #assodiv:hover ~ #assotxt {
   display: block !important;
   background-color: white;
 }

Javascript可能是这里的方式,但我在这方面有点新手。

非常感谢您的帮助。

4 个答案:

答案 0 :(得分:1)

您还可以使用jquery隐藏并在悬停事件中显示所需的div:

FEED_EXPORTERS = {
    'json': 'myproject.exporters.Utf8JsonItemExporter',
}
$(document).ready(function(){
$('#assodiv').on( "mouseenter",function() {
  $('#assotxt').show();
  $('#assotxt').css("background-color", "white");
  $("#assotxt").appendTo($("#assotxt_target"));

});
$('#assodiv').on( "mouseleave",function() {
   $('#assotxt').hide();
 });
});
.btn {
  text-decoration: none;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  padding: 0 15px;
  line-height: 32px;
  height: auto;
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 100px;
  text-align: center;
  text-transform: uppercase;
  margin-top: 20px;
  margin-bottom: 20px;
  cursor: pointer;
}

.btn.blue {
  background-color: #19ace4;
}

.btn.blue:hover {
  opacity: 0.85;
}

.btn.pill {
  -webkit-border-radius: 16px;
  -moz-border-radius: 16px;
  border-radius: 16px;
}


/* - - - MOBLE VIEW - - - */

@media only screen and (max-width: 640px) {
  .mobileViewDiagram {
    display: block !important;
    margin-left: auto;
    margin-right: auto;
    transform: scale(0.7);
    margin-top: -50px;
    margin-bottom: -50px;
  }
  .HybridDiagram,
  #leftWrapper,
  #rightWrapper {
    display: none;
  }
}


/* - - - DESKOTP VIEW - - - */

section {
  width: 100%;
  height: 476px;
  margin: auto;
}

div#leftWrapper {
  width: 50%;
  height: 476px;
  float: left;
}

div#rightWrapper {
  margin-left: 50%;
  height: 476px;
}

.diagramTextWrapper {
  display: block;
  margin: auto;
  text-align: center;
  padding-left: 50px;
  padding-right: 50px;
  padding-top: 20px;
}

.HybridDiagram {
  width: 476px;
  height: 476px;
}

.HybridDiagram img {
  max-width: 100%;
  position: absolute;
}


/* Associates */

.HybridDiagram img:nth-child(1) {
  left: 0;
  top: 0;
}


/* Staff */

.HybridDiagram img:nth-child(2) {
  left: 244px;
  top: 0;
}


/* Client */

.HybridDiagram img:nth-child(3) {
  left: 38px;
  top: 301px;
}

.mobileViewDiagram {
  display: none;
}

#asso:hover,
#staff:hover,
#client:hover {
  opacity: 0.85;
}

/* My attempt */
#assotxt {
  display: none;
}

#assodiv:hover ~ #assotxt {
  display: block !important;
  background-color: white;
}

答案 1 :(得分:1)

普通JS:

<script>

将其插入身体标记

底部的###define arrays $array1 = @("bill","eric","james","sarah") $array2 = @("bill","scott","sarah","nancy") ###Combine/Filter? arrays and remove users that exist in both arrays $result = ($array1 + $array2 | some fancy match removal goes here) $result eric,james,scott,nancy 块中

答案 2 :(得分:1)

你可以试试这个。

将此添加到头部:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

添加此javascript:

var asso = $('#asso');

asso.on('mouseenter',function(){
  $('.diagramTextWrapper').prepend('<p class="wrapper_text">test</p>');
});

asso.on('mouseleave',function(){
  $('.wrapper_text').remove();
});

答案 3 :(得分:0)

#assotxt不是#assodiv的兄弟;还应在:hover元素处应用.mobileViewDiagram吗?您可以在:hover:after使用.mobileViewDiagram,并将content设置为要显示的文字。使用topleft属性在视口中的适当位置呈现文本。

.mobileViewDiagram:hover:after {
  display: block !important;
  background-color: white;
  content:"This should appear on top of existing text inside rightWrapper.";
  position:absolute; /* use `top`, `left`, `right` to set position of `content` */
}

jsfiddle https://jsfiddle.net/vhswx2jg/2/