【问题标题】:how to highlight a certain piece of text when a user has dragged the cursor over it in jQuery当用户在jQuery中将光标拖到某段文本上时如何突出显示该段文本
【发布时间】:2019-09-29 13:36:48
【问题描述】:

当用户在 jQuery 中将光标拖到某段文本上时,我无法突出显示该段文本

我尝试过使用 jQuery 提供给您的 .select() 函数,但它似乎没有在

上工作

这是一个例子

<div>
  Some random text <span class="highlighted_text">Highlighted text</span>
</div>

当用户将光标拖到某个文本上时,它会包裹在标签中他们拖过的文本上

谢谢,

阿纳夫 ????

【问题讨论】:

  • 你说拖动的时候是指鼠标悬停吗?
  • 就像当用户将光标拖到某个文本上时,它会在他们选择的文本上创建蓝色背景色????
  • Get the Highlighted/Selected text 这是您要找的东西吗?

标签: javascript jquery cursor highlight


【解决方案1】:

您可以使用 CSS 将其突出显示,只需这样做:

CSS:

.highlighted_text:hover {
    background-color: blue;
    color: white;
}

HTML:

<div>
  Some random text <span class="highlighted_text">Highlighted text</span>
</div>

但是如果你想在鼠标失去焦点后仍然突出显示文本部分,你必须让它更复杂一点,像这样:

CSS:

@keyframes hover {
  0% {
    color: #000;
  }
  100% {
    background-color: #00F;
    color: #FFF;
  }
}

.highlighted_text {
  animation-name: hover;
  animation-duration: 1000ms;
  animation-fill-mode: both;
  animation-play-state: paused;      
}

.highlighted_text:active,
.highlighted_text:focus,
.highlighted_text:hover {
  animation-play-state: running;
}

HTML:

<div>
  Some random text <span class="highlighted_text">Highlighted text</span>
</div>

【讨论】:

  • 当用户突出显示一段文本时,他们可以将他们在 他们突出显示的部分中突出显示的那段文字包装起来
猜你喜欢
  • 2011-09-17
  • 2011-04-23
  • 1970-01-01
  • 1970-01-01
  • 2012-09-08
  • 2018-05-01
  • 2013-11-11
  • 2011-06-26
  • 2023-03-15
相关资源
最近更新 更多