在hover / mouseover上更改div内的文本和svg的颜色

时间:2016-01-20 00:54:01

标签: javascript css

我已经尝试为文本实现添加/删除类并且它有效,但问题是当鼠标移出转换时,它是如何被保留的?

$(document).ready(function() {
  $('#bookmark').mouseover(function() {
    $('#text').addClass('light-blue-link')
  });
  $('#bookmark').mouseout(function() {
    $('#text').removeClass('light-blue-link')
  });
});
.light-blue-link {
  color: rgb(88, 202, 230);
  transition: color 1s ease;
}


.button {
  height: 30px;
  width: auto;
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='bookmark' class='button'>
  <span id='text' class=''>Text</span>
</div>

1 个答案:

答案 0 :(得分:1)

它没有在function insertData($post) $dbc = mysqli_connect(DB_HOST, DB_UN, DB_PW, DB_NAME); foreach ($post as $key => $value) { $post[$key] = mysqli_real_escape_string($dbc, $value); } $insert = 'INSERT INTO products_test ('.array_keys($entry)[0].','.array_keys($entry)[1].') VALUES ("'.array_values($entry)[0].'","'.array_values($entry)[1].'")'; if (mysqli_query($dbc, $insert)) { echo htmlspecialchars($post['name']).' has been added to the inventory'; } $post = [ 'name' => $_POST['name'], 'narrative' => $_POST['narrative'] ]; insertData($post); 上转换,因为删除了类时删除了mouseout属性。如果您希望元素在transitionmouseover上进行转换,即使删除了类,mouseout属性也应保持更改,因此您需要将转换添加到transition直接元素(而不是添加然后删除的类):

&#13;
&#13;
#text
&#13;
$('#bookmark').mouseover(function() {
  $('#text').addClass('light-blue-link')
});
$('#bookmark').mouseout(function() {
  $('#text').removeClass('light-blue-link')
});
&#13;
#text {
  transition: color 1s ease;
}
.light-blue-link {
  color: rgb(88, 202, 230);
}
.button {
  height: 30px;
  width: auto;
  cursor: pointer;
}
&#13;
&#13;
&#13;

作为旁注,根据您实际尝试做的事情,您可能不需要jQuery:

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='bookmark' class='button'>
  <span id='text'>Text</span>
</div>
&#13;
#text {
  transition: color 1s ease;
}
.button:hover #text {
  color: rgb(88, 202, 230);
}
.button {
  height: 30px;
  width: auto;
  cursor: pointer;
}
&#13;
&#13;
&#13;