CSS3 转换——备用触发器?

发布于 2024-11-02 12:43:07 字数 892 浏览 1 评论 0原文

无用的背景信息

大家好。这是我在这里发表的第一篇文章,但我经常来这里寻求帮助。 我是一名业余网页设计师,从事网页设计已经快一年了。

问题

我的问题是关于 CSS3 转换的。我的页面中心有一个小的圆形元素,当我将鼠标悬停在它上面时,它会成功转换。我有一个更大的圆形元素,按 z 索引,位于它的下面。较大的圆圈也有在​​ CSS 中编码的 CSS3 变换,但不会变换,甚至在悬停时不会触发。两个圆重叠,最小的在上面,形成同心圆。

我尝试的解决方案

一个词:Z-index。我尝试过将较大的圆圈放在上面,效果很好。问题是较小的圆圈不再触发...

我想要的结果

我希望圆圈保持在“同心”位置,而外部的较大圆圈通过:悬停进行变换。是否有可能有“备用触发器”?例如:在 JavaScript 中,我可以通过将鼠标悬停在我指定的任何元素上来触发动画。这可以在 CSS 中实现吗?我可以将鼠标悬停在元素 (I) 上并更改元素 (II) 的属性吗?如果我不能做到这一点,我将如何通过仅将鼠标悬停在一个圆圈上来触发两个圆圈的动画?我试图继续使用纯 CSS/HTML,但我会接受 JavaScript 答案。

最后的注释

我希望我已经提供了足够的信息以获得一个体面的答案...这是一个屏幕截图:https:// i.sstatic.net/WPj62.png 带有无穷大符号的圆是较小的圆元素。屏幕周围带有模糊边框的较大圆圈是另一个元素。

编辑:

有些事情仍然不对,请查看此处发布的完整代码:http:// cssdesk.com/eJ8BH

Usless Background Info

Hello, all. This is my first post here, but I often come here for help.
I am an amateur web designer and have been in web designing for almost a year now.

The Problem

My question is about CSS3 transforms. I have a small, circular element in the center of my page that transforms successfully when I hover over it. I have a larger circular element that is, by z-index, underneath it. The larger circle also has CSS3 transforms coded in the CSS, but will not transform, or even triggerd when hovered over. Both circles are overlaid, with the smallest on top, to create concentric circles.

My Attempted Solution

One word: Z-index. I have tried putting the larger circle on top, which works fine. The problem with this is that the smaller circle no longer triggers...

The Result I Want

I would like for the circles to remain in their 'concentric' positions and for the larger circle on the outside to transform by :hover. Is it possible to have an 'alternate trigger'? e.g.: in JavaScript, I can trigger an animation by hovering over any element that I specify. Is this possible to do in CSS? Can I hover element (I), and change properties for element (II)? If I cannot do this, how would I go about triggering animations for both circles, by hovering over only one? I am trying to stay with pure CSS/HTML, but I will accept JavaScript answers.

Last Notes

I hope I have provided ample info for a decent answer... Here is a screenshot: https://i.sstatic.net/WPj62.png
The circle with the infinity sign is the smaller circle element. The larger circle with the faint border around the screen is the other element.

EDIT:

Something's still not right, please take a look at the full code posted here: http://cssdesk.com/eJ8BH

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

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

发布评论

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

评论(2

情释 2024-11-09 12:43:07

如果我理解你的问题,听起来当你将鼠标悬停在小圆圈上时,你希望大圆圈和小圆圈都变形,对吗?

最简单的方法可能是使用 javascript 来实现此目的。如果您使用 jQuery,那就更容易了:

$('.littleCircle')
    .hover(function(){
        $(this).addClass('myTransformationClass');
        $('.biggerCircle').addClass('myTransformationClass');
})

更新:基于后续反馈的一些进一步示例。

这就是我要做的。首先,为所有 4 个相关元素指定一个类,以便您可以通过 jQuery 获取它们。对于我使用 .rolloverSet 的示例

// grab all 4 elements and cache them
$rolloverSet = $('.rolloverSet');

// grab the one element that needs to have two classes
$otherElement = $rolloverSet.find('.otherElement');

$rolloverSet
    .hover(function(){ // we'll add a hover event to each element in the group
        $(this).addClass('myTransformationClass');
        $otherElement.addClass('myOtherTransformationClass');
    })
    .blur(function(){ // remove the classes on mousout
        $(this).removeClass('myTransformationClass');
        $otherElement.removeClass('myOtherTransformationClass');
    })

If I understand your question, it sounds like when you hover over the small circle, you want both the large and small circle to transform, correct?

The easiest way is likely to use javascript for this. If you are using jQuery, it's even easier:

$('.littleCircle')
    .hover(function(){
        $(this).addClass('myTransformationClass');
        $('.biggerCircle').addClass('myTransformationClass');
})

UPDATE: Some further examples based on follow-up feedback.

Here's what I'd do. First, give all 4 related elements a class so you can grab them via jQuery. For the example I use .rolloverSet

// grab all 4 elements and cache them
$rolloverSet = $('.rolloverSet');

// grab the one element that needs to have two classes
$otherElement = $rolloverSet.find('.otherElement');

$rolloverSet
    .hover(function(){ // we'll add a hover event to each element in the group
        $(this).addClass('myTransformationClass');
        $otherElement.addClass('myOtherTransformationClass');
    })
    .blur(function(){ // remove the classes on mousout
        $(this).removeClass('myTransformationClass');
        $otherElement.removeClass('myOtherTransformationClass');
    })
何时共饮酒 2024-11-09 12:43:07

为此,您不需要 jQuery。您需要在同心圆的父元素上应用 :hover ,然后将动画应用到其直接子元素,如下所示: http://jsfiddle.net/nimbu/taqr4/

我更改的内容:

  • 更新为使用较短的过渡、动画属性
  • 添加了 moz、o、无前缀属性
  • 从 border-radius 中删除了 -webkit-
  • 收集同心圆的共同属性以防止重复
  • 修复不正确的背景颜色(#00000000)

You do not need jQuery for this. You need to apply :hover on the parent element of the concentric circles and then apply the animation to its immediate children like this: http://jsfiddle.net/nimbu/taqr4/

Things I changed:

  • Updated to use shorter transitions, animations property
  • Added moz, o, unprefixed properties
  • Removed -webkit- from border-radius
  • Gathered common properties of concentric circles to prevent repetition
  • Fixed incorrect background-color (#00000000)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文