gpt4 book ai didi

javascript - 是否可以制作一条波浪线?

转载 作者:技术小花猫 更新时间:2023-10-29 12:13:00 25 4
gpt4 key购买 nike

如果我想做一条水平线,我会这样做:

<style>
#line{
width:100px;
height:1px;
background-color:#000;
}
</style>
<body>
<div id="line"></div>

如果我想做一条垂直线,我会这样做:

#line{
width:1px;
height:100px;
background-color:#000;
}
</style>
<body>
<div id="line"></div>

曲线比较棘手,但可以使用 border-radius 并包裹元素:

<style>
.curve{
width:100px;
height:500px;
border:1px #000 solid;
border-radius:100%;
}
#wrapper{
overflow:hidden;
width:40px;
height:200px;
}
</style>
<body>
<div id="wrapper">
<div class="curve"></div>
</div>
</body>

但我什至无法理解如何生成波浪线! 仅使用 css(和 javascript,因为它似乎确实有必要能够更轻松地生成它们)是否甚至可以远程实现?

注意事项:

正如预期的那样,鉴于您的回答,没有办法在单独的 css 中执行此操作...javascript 和 jquery 100% 适合您的回答...不能使用图像

最佳答案

这个问题相当老了,但我找到了一种无需 Javascript、重复的 CSS 或图像的方法。

使用 background-size 你可以重复一个图案,它可以用纯 CSS 使用线性渐变或径向渐变创建。

我在这里放了一堆例子:http://jsbin.com/hotugu/edit?html,css,output

example

基本要点是:

.holder {
/* Clip edges, as some of the lines don't terminate nicely. */
overflow: hidden;
position: relative;
width: 200px;
height: 50px;
}

.ellipse {
position: absolute;
background: radial-gradient(ellipse, transparent, transparent 7px, black 7px, black 10px, transparent 11px);
background-size: 36px 40px;
width: 200px;
height: 20px;
}

.ellipse2 {
top: 20px;
left: 18px;
background-position: 0px -20px;
}
<div class="holder">
<div class="ellipse"></div>
<div class="ellipse ellipse2"></div>
</div>

您可以通过一些修改生成一些令人信服的波浪线:

.holder {
position: relative;
width: 200px;
height: 50px;
top: 25px;
}
.tinyLine {
position: absolute;
/* Cuts off the bottom half of the pattern */
height: 20px;
/* For better cross browser consistency, make it larger with width. */
width: 1000%;
/* And then scale it back down with scale, recentering with translateX. */
transform: translateX(-45%) scale(0.1);
}

.tinyLine1 {
background: linear-gradient(45deg, transparent, transparent 49%, red 49%, transparent 51%);
}
.tinyLine2 {
background: linear-gradient(-45deg, transparent, transparent 49%, red 49%, transparent 51%);
}
.tinyLine {
/* Must be after background definition. */
background-size: 40px 40px;
}
<div class="holder">
<div class="tinyLine tinyLine1"></div>
<div class="tinyLine tinyLine2"></div>
</div>

浏览器支持还可以 ( http://caniuse.com/#feat=css-gradients ),IE 10 可能会工作,但是在不同的浏览器中会出现小范围的问题。如果您希望它在非常小的尺度上始终如一地工作,您可能希望在更大的尺度上制作线条,然后使用 transform: scale(x); 缩小它。

它也应该非常快,线性渐变在 Chrome 中的 GPU 上呈现。

关于javascript - 是否可以制作一条波浪线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17285514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com