如何使用 javascript 或 jquery 使图像或按钮在鼠标悬停时发光?

发布于 2024-11-13 12:03:10 字数 295 浏览 2 评论 0原文

我想在将鼠标悬停在按钮或图像上时添加发光效果。如何使用 javascript、jquery 或 CSS 执行此操作?这是我希望它看起来的示例 http://www.flashuser.net/flash-menus /tutorial-flash-glow-buttons-menu.html

有人能给我一些示例代码吗?

提前致谢

I want to add a glowing effect when I mouse over a button or image. How do I do this with javascript, jquery, or CSS? Here is an example of what I want it to look
http://www.flashuser.net/flash-menus/tutorial-flash-glow-buttons-menu.html

Can someone give me some sample code?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦途 2024-11-20 12:03:10

如果您不介意针对现代浏览器,您可以使用 CSS 过渡和 box-shadow 属性,无需 JS。

在这里查看这个网站:
http://designshack .co.uk/articles/css/5-cool-css-hover-effects-you-can-copy-and-paste
(向下滚动,直到看到淡入和反射)

此处演示:
http://designshack.co.uk/tutorialexamples/HoverEffects/Ex5.html

If you dont mind targeting modern browsers you can use CSS transitions and box-shadow properties, no JS needed.

Check out this site here:
http://designshack.co.uk/articles/css/5-cool-css-hover-effects-you-can-copy-and-paste
(Scroll down until you see Fade-in and Reflect)

Demo here:
http://designshack.co.uk/tutorialexamples/HoverEffects/Ex5.html

独享拥抱 2024-11-20 12:03:10

发布 Radioactive Buttons 绝对是一个好时机,它是纯 CSS3 的。但仅限 Webkit 浏览器(例如 Chrome 和 Safari)。这是一个修改后的版本,仅在悬停时发光,这样不会分散注意力:

@-webkit-keyframes greenPulse {
  from { background-color: #749a02; -webkit-box-shadow: 0 0 0 #333; }
  to { background-color: #91bd09; -webkit-box-shadow: 0 0 18px #91bd09; }
}

a.green.button {
  background-color: #749a02;
  border-radius: 0.5em;
  color: #fff;
  padding: 0.5em;
  text-decoration: none;
}

a.green.button:hover {
  background-color: #91bd09;
  -webkit-animation-name: greenPulse;
  -webkit-animation-duration: 2s;
  -webkit-animation-iteration-count: 1;
  -webkit-box-shadow: 0 0 18px #91bd09;
}

<a href="#" class="green button">Click Me</a>

jsFiddle 演示。随着更多浏览器采用它,它应该会变得更容易,但在那之前这只是基于 JavaScript 的解决方案的一个附加组件。

Never a bad time to post Radioactive Buttons, which is pure CSS3. Only Webkit browsers though (e.g. Chrome and Safari). Here's a modified version that just glows on hover, which is much less distracting:

@-webkit-keyframes greenPulse {
  from { background-color: #749a02; -webkit-box-shadow: 0 0 0 #333; }
  to { background-color: #91bd09; -webkit-box-shadow: 0 0 18px #91bd09; }
}

a.green.button {
  background-color: #749a02;
  border-radius: 0.5em;
  color: #fff;
  padding: 0.5em;
  text-decoration: none;
}

a.green.button:hover {
  background-color: #91bd09;
  -webkit-animation-name: greenPulse;
  -webkit-animation-duration: 2s;
  -webkit-animation-iteration-count: 1;
  -webkit-box-shadow: 0 0 18px #91bd09;
}

<a href="#" class="green button">Click Me</a>

jsFiddle demo. It should make it easier as more browsers adopt it, but until then this is just an add-on to the JavaScript-based solutions.

情深如许 2024-11-20 12:03:10

使用 CSS 也可以实现相同的效果:

HTML

 <img class="opacity_img" src="image.png" alt="" />

CSS 对于 IE

 .opacity_img{
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=45)"; 
  filter:alpha(opacity=45);
 }
 .opacity_img:hover{
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  filter:alpha(opacity=100);
 }

CSS 对于其他浏览器:

 .opacity_img{
  opacity: 0.45;
 }
 .opacity_img:hover{
  cursor:pointer;
  opacity: 1.0;
 }

Using CSS also you can achieve the same:

HTML

 <img class="opacity_img" src="image.png" alt="" />

CSS for IE:

 .opacity_img{
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=45)"; 
  filter:alpha(opacity=45);
 }
 .opacity_img:hover{
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  filter:alpha(opacity=100);
 }

CSS for other browsers:

 .opacity_img{
  opacity: 0.45;
 }
 .opacity_img:hover{
  cursor:pointer;
  opacity: 1.0;
 }
吻泪 2024-11-20 12:03:10

liza给出了一个很棒的答案——只用几行代码就达到了效果。

但如果您希望它更平滑,您可以通过添加以下内容来使不透明度过渡持续一段时间:

 .opacity_img{
  opacity: 0.45;
  transition: opacity 0.5s;
 }
 .opacity_img:hover{
  cursor:pointer;
  opacity: 1.0;
  transition: opacity 0.5s;
 }

liza gave a great answer - the effect achieved only in few lines of code.

But if you'd like it more smooth you can make opacity transition last some time by adding:

 .opacity_img{
  opacity: 0.45;
  transition: opacity 0.5s;
 }
 .opacity_img:hover{
  cursor:pointer;
  opacity: 1.0;
  transition: opacity 0.5s;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文