有没有一种简单的方法使用 JQuery 向 div 添加牙齿?
基本的 div 是一个矩形。但有些网站(如 Facebook)顶部有一个小“牙齿”,指向图片或其他东西。
它给了它一颗向外的牙齿。
在 JQuery 中是否有一种简单的方法可以做到这一点?
A basic div is a rectangle. But some websites (like Facebook) have little "tooth" on the top of it, pointing to the picture or something.
It gives it a outward tooth.
Is there an easy easy easy way to do this in JQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种“简单”的方法是将绝对定位的图形添加到
中:(
未经测试)
如果您的
有边框,则您可以可以让图形重叠并将边框“延伸”到箭头的尖端。
或者,我已经看到仅使用顶部带有“牙齿”的背景图像(下面丑陋的 ASCII 草图)即可实现此目的:
然后您只需要确保:
有将此图像作为背景图像(无重复、顶部、左侧),
(两个方向),并且
有一个额外的顶部填充(等于箭头的“大小”)。
One "easy" way would be to add an absolutely positioned piece of graphic to the
<div>
:(Untested)
If your
<div>
has a border, you could let the graphics overlap and "extend" the border to the tip of the arrow.Alternatively, I've seen this achieved using only a background image with the "tooth" on the top (ugly ASCII sketch below):
Then you just need to make sure that:
<div>
has this image as background image (no-repeat, top, left),<div>
(both directions), and<div>
has an extra top-padding (equal to the "size" of the arrow).不确定这是否是您正在寻找的...有一种纯 CSS 方法可以做到这一点,我经常这样做。除其他地方外,此处对此进行了描述。
要使牙齿朝上,请为牙齿添加一个
div
:然后使用 0 像素矩形上的粗底部边框对其进行样式设置...您需要将其绝对定位并调整位置它出现了。
jQuery 插件可能看起来像这样:
CSS 需要大量调整。
创建一个空心三角形有点困难,因为您需要两个矩形相互遮盖。我已经完成了这个(实际上还完成了更复杂的事情),但说实话,创建图形,然后添加它并以类似的方式定位它可能更容易。
Not sure if this what you're looking for... There's a pure CSS way to do this, which I do quite a bit. It's described here, among other places.
To make a tooth pointing up, add a
div
for the tooth: and then style it using a thick bottom border on a 0 pixel rectangle...You'll need to position it absolutely and and adjust where it shows up.
As a jQuery plugin might look something like:
The CSS will need lots of tweaking.
Creating a hallowed out triangle is a little more difficult, as you need to two rectangles masking each other. I've done this (and more complex things, actually), but to be honest, it's probably just easier to create a graphic, and then add it and position it in a similar manner.