- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我现在正在研究 SVG,并卡在径向渐变主题上,关于精确移动径向渐变中心。比方说,我有 2 个渐变示例 ( codepen snippet to play around )。一个基本的(完美运行):
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"xmlns:xlink="http://www.w3.org/1999/xlink"width="200px" height="200px" viewBox="0 0 200 200">
<title>Bulls-eye Repeating Radial Gradient</title>
<radialGradient id="bullseye"cx="50%" cy="50%" r="10%" spreadMethod="repeat">
<stop stop-color="tomato" offset="50%"/>
<stop stop-color="#222" offset="50%"/>
</radialGradient>
<rect width="100%" height="100%" rx="10%"fill="url(#bullseye)"/>
</svg>
还有一个示例,我尝试应用 fx
和 fy
属性来移动渐变焦点:
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"xmlns:xlink="http://www.w3.org/1999/xlink"width="200px" height="200px" viewBox="0 0 200 200">
<title>Bulls-eye Repeating Radial Gradient</title>
<radialGradient id="bullseye2" cx="50%" cy="50%" r="10%" fx=".2" fy=".2" spreadMethod="repeat">
<stop stop-color="tomato" offset="50%"/>
<stop stop-color="#222" offset="50%"/>
</radialGradient>
<rect width="100%" height="100%" rx="10%"fill="url(#bullseye2)"/>
</svg>
在这里它只是切割了一 block 形状而不是仅仅移动了一个中心点。
你能解释一下我在这里做错了什么以及为什么它以如此奇怪的方式工作吗?
最佳答案
定义径向渐变时有两个主要概念:
稍后我会提到“重复”选项,但现在:渐变从焦点向外渲染,直到到达外部形状。也许这有助于想象外部形状在到达焦点之前不断缩小。
这意味着如果焦点在定义的形状内,它会显得相当直观:
<svg viewBox="0 0 120 120" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="Gradient" cx="0.5" cy="0.5" r="0.5"
fx="0.35" fy="0.35">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<rect x="10" y="10" width="100" height="100"
fill="url(#Gradient)" />
<circle cx="60" cy="60" r="50" fill="transparent" stroke="white" stroke-width="1"/>
<circle cx="45" cy="45" r="2" fill="white" stroke="white"/>
<circle cx="60" cy="60" r="2" fill="white" stroke="white"/>
<text x="38" y="40" fill="white" font-family="sans-serif" font-size="10pt">(fx,fy)</text>
<text x="63" y="63" fill="white" font-family="sans-serif" font-size="10pt">(cx,cy)</text>
</svg>
(示例取自 MDN,稍作修正和微调)
但是,如果焦点在边界形状之外,您最终会得到更像圆锥体的东西:
<svg viewBox="0 0 120 120" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="Gradient" cx="0.5" cy="0.5" r="0.5"
fx="0.05" fy="0.05">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<rect x="10" y="10" width="100" height="100"
fill="url(#Gradient)" />
<circle cx="60" cy="60" r="50" fill="transparent" stroke="white" stroke-width="1"/>
<circle cx="15" cy="15" r="2" fill="white" stroke="white"/>
<circle cx="60" cy="60" r="2" fill="white" stroke="white"/>
<text x="28" y="30" fill="white" font-family="sans-serif" font-size="10pt">(fx,fy)</text>
<text x="63" y="63" fill="white" font-family="sans-serif" font-size="10pt">(cx,cy)</text>
</svg>
请注意,它仍然采用圆圈并将其“缩小”到焦点,但由于焦点现在位于圆圈之外,因此它无法为锥体之外的点定义任何有意义的颜色。
您可以使用 fx
和 fy
移动焦点。还有 fr
有时有用但暂时忽略它;无论如何,您都可以对色标位置执行相同的操作。
您使用cx
、cy
和r
移动圆圈。
移动两者的效果只是平移渐变。
重复使这有点困惑,但也许这个演示会澄清:
<svg viewBox="0 0 120 120" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="Gradient" cx="0.5" cy="0.5" r="0.3"
fx="0.4" fy="0.4" spreadMethod="repeat">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<rect x="10" y="10" width="100" height="100"
fill="url(#Gradient)" />
<circle cx="60" cy="60" r="30" fill="transparent" stroke="white" stroke-width="1"/>
<circle cx="50" cy="50" r="2" fill="white" stroke="white"/>
<circle cx="60" cy="60" r="2" fill="white" stroke="white"/>
<text x="38" y="40" fill="white" font-family="sans-serif" font-size="10pt">(fx,fy)</text>
<text x="63" y="63" fill="white" font-family="sans-serif" font-size="10pt">(cx,cy)</text>
</svg>
白色圆圈仍然定义了形状,因此为了直观的结果,焦点应该在它里面。
在您发布的示例中,渐变本身非常小;仅占据中心周围 10 个像素的半径。它定义了单一的颜色过渡。条纹效果是由于 repeat
选项。这是您的示例,其中显示了焦点和外部形状:
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"xmlns:xlink="http://www.w3.org/1999/xlink"width="200px" height="200px" viewBox="0 0 200 200">
<title>Bulls-eye Repeating Radial Gradient</title>
<radialGradient id="bullseye"cx="50%" cy="50%" r="10%" spreadMethod="repeat">
<stop stop-color="tomato" offset="50%"/>
<stop stop-color="#222" offset="50%"/>
</radialGradient>
<rect width="100%" height="100%" fill="url(#bullseye)"/>
<circle cx="50%" cy="50%" r="10%" fill="transparent" stroke="white" stroke-width="1"/>
<circle cx="50%" cy="50%" r="2" fill="white" stroke="white"/>
</svg>
这是您的第二个示例(为清楚起见,这次焦点以黑色显示):
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"xmlns:xlink="http://www.w3.org/1999/xlink"width="200px" height="200px" viewBox="0 0 200 200">
<title>Bulls-eye Repeating Radial Gradient</title>
<radialGradient id="bullseye"cx="50%" cy="50%" fx=".2" fy=".2" r="10%" spreadMethod="repeat">
<stop stop-color="tomato" offset="50%"/>
<stop stop-color="#222" offset="50%"/>
</radialGradient>
<rect width="100%" height="100%" fill="url(#bullseye)"/>
<circle cx="50%" cy="50%" r="10%" fill="transparent" stroke="white" stroke-width="1"/>
<circle cx="20%" cy="20%" r="2" fill="black" stroke="black"/>
</svg>
关于SVG 径向渐变 - 移动焦点(中心),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59694933/
我需要一些帮助。这都是关于选项卡索引的。我有一个使用 document.getElementById("name").focus(); 的 JavaScript,其中 id="name"的 textb
这是我的第一篇文章,如果您想了解更多信息,请告诉我! 我正在使用选择列表和 jQuery Accordion 。当用户从列表中选择一个值时,它会使用 activate 方法打开折叠面板的相关部分。 除
JQM 1.3.2/ASP.NET MVC 4 当选择一个值时,焦点没有正确设置到输入字段,我错过了什么? 周围的典型 jqm-shadow 没有从选择中移除,输入得到阴影效果,但光标没有设置到输入字
我正在为 Android 开发一个播放列表应用程序,它有一个包含歌曲名称 (TextView) 作为其列表项的 ListView。 随着歌曲的播放,我想突出显示 ListView 中的项目,直到歌曲结
我在这里不知所措,以前从来没有遇到过这个问题。 我无法让 focus() 在任何浏览器中工作。我正在使用 jquery,甚至不能让它与标准的 javascript 一起工作。我也尝试添加超时但仍然没有
登录后我有一个文本字段。登录后光标将自动聚焦在该文本字段上。如何验证该文本字段上是否存在光标/焦点? 文本框的HTML代码如下: 最佳答案 您也可以尝试直接的 webdriver 方法: drive
我有一个框架和一个面板。我永久删除面板并添加另一个面板。添加新面板后,我需要 JTextField 来获得焦点。我该怎么做? 我尝试了 panel.requestFocus() 方法,但没有成功。 示
这个问题在这里已经有了答案: 关闭 13 年前。 Possible Duplicate: Trouble with jquery lavalamp 出于某种原因,无论我点击哪个链接,我的背景颜色都会
在我的表单验证中,在提交时,我正在验证表单,并找到未填充的元素并使用此函数进行聚焦:工作正常 switch (tagName) { case 'TEXT': if (!actualVa
我最近构建了一个 JS/CSS 模态系统。该元素使用的是 Bootstrap 模式,但通过在其中放置无法滚动或无法正确聚焦在移动设备上的表单和大量内容,将其推向了极限。 可以触发模态系统here单击大
我正在建立一个网站,但我想将图片放在背景中,但我无法将其放在我想要的位置。 我希望网页上图像的“焦点”位于图像中心几像素处。宽度我都能看出来,但是高度没有。 图像分辨率为“5760x3840px”。
这个问题在这里已经有了答案: using :focus pseudo class on li or other element else than a,input,button, etc (2 个
每当我创建编辑器的另一个实例(在我的例子中,通过 onkeypress 事件),我就会失去对创建新编辑器时正在输入的编辑器的关注。我怎样才能防止所有编辑都失去对任何事件的关注? 最佳答案 为此,Qui
我试图将焦点放在一个字段上,更改文本的颜色,但无论我尝试什么:它都不起作用。以下是 HTML: .register-section input:focus + .register-section la
我已经为微调器选择的变化设置了一个监听器。在监听器中,我想关注一个 EditText 字段。我使用了以下代码: text_other_msg.setFocusable(true); 它不起作用。我还尝
我在表单屏幕上有几个 UITextField 输入,其中一些有一个数字键盘显示,通过自定义弹出窗口显示。当用户在字段中前进时,我们会根据需要关闭或打开弹出窗口。在 iOS 11 中,似乎“第一响应者”
我在 jQueryUI 中输入焦点时遇到问题。我在按钮上使用了 hover() 方法并且它正在工作,但是输入上的 focus() 不起作用。我不知道为什么。这是代码和 fiddle $(documen
有没有办法在自动对焦完成后随时获取对焦点? 在 Apple 的示例代码中,他们使用: - (void)subjectAreaDidChange:(NSNotification *)notifi
如果我的焦点不在 textField 上,如何移除 NSTextField 上的焦点? 我有一个 NSTextField,我设置了操作:编辑结束时发送。单击 textField 后,当我单击 View
如何通过 jQuery 实现这一点? 当用户单击表单中的任何输入时,它就会获得焦点。当用户从任何输入中单击表单外时,它会变得模糊,但是,在表单本身的输入之间进行 Tab 键切换之间不会触发模糊。 对于
我是一名优秀的程序员,十分优秀!