你如何让一个元素“闪光"?在 jQuery 中 [英] How do you make an element "flash" in jQuery

查看:27
本文介绍了你如何让一个元素“闪光"?在 jQuery 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 jQuery 的新手,并且有一些使用 Prototype 的经验.在 Prototype 中,有一种方法可以闪烁"一个元素 —IE.用另一种颜色简单地突出显示它并让它逐渐恢复正常,以便用户的眼睛被它吸引.jQuery 中有这样的方法吗?我看到了淡入、淡出和动画,但我没有看到像闪光"这样的东西.也许这三个中的一个可以与适当的输入一起使用?

I'm brand new to jQuery and have some experience using Prototype. In Prototype, there is a method to "flash" an element — ie. briefly highlight it in another color and have it fade back to normal so that the user's eye is drawn to it. Is there such a method in jQuery? I see fadeIn, fadeOut, and animate, but I don't see anything like "flash". Perhaps one of these three can be used with appropriate inputs?

推荐答案

我的方式是 .fadein, .fadeout .fadein, .fadeout ......

My way is .fadein, .fadeout .fadein, .fadeout ......

$("#someElement").fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);

function go1() { $("#demo1").fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100)}

function go2() { $('#demo2').delay(100).fadeOut().fadeIn('slow') }

#demo1,
#demo2 {
  text-align: center;
  font-family: Helvetica;
  background: IndianRed;
  height: 50px;
  line-height: 50px;
  width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button onclick="go1()">Click Me</button>
<div id='demo1'>My Element</div>
<br>
<button onclick="go2()">Click Me</button> (from comment)
<div id='demo2'>My Element</div>

这篇关于你如何让一个元素“闪光"?在 jQuery 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆