简体   繁体   English

我必须将闪烁的管道添加到特定的占位符中

[英]I have to add blinking pipe into an specific placeholder

I need to include a blinking pipe (as if it were a cursor) at the end of my placeholder. 我需要在占位符的末尾包含一个闪烁的管道(好像它是一个光标)。 It is a component in liquid code. 它是液体代码中的一个组成部分。

I tried to pass a variable with the blinking content through javascript and more recently an infinite animation of 1s in my sass file, but there is no way to do that and I don't know how. 我尝试通过javascript传递带闪烁内容的变量,最近在我的sass文件中传递1s的无限动画,但是没有办法做到这一点,我不知道如何。

This is my input: 这是我的意见:

<input type="email"
 name="contact[email]"
 id="{{ formId }}-email"
 class="input-group__field{% if form.errors %} input--error{% endif %}"
 value="{{ form.email }}"
 placeholder="{{ 'general.newsletter_form.email_placeholder' | t }}"
 {% if form.errors %}
  aria-invalid="true"
  aria-describedby="{{ formId }}-email-error"
  data-form-status
 {% endif %}
>

I can't add via css the animation like this 我无法通过css添加这样的动画

@-webkit-keyframes blink {
    from {
        opacity: 1.0;
    }
    to {
        opacity: 0.0;
    }
}
blink {
    -webkit-animation-name: blink;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: cubic-bezier(1.0, 0, 0, 1.0);
    -webkit-animation-duration: 1s;
}

because i can't asign a class or id only in some part of placeholder 因为我不能仅仅在占位符的某个部分中设置类或id

Maybe something like this in sass could be work? 也许在萨斯这样的事情可能有用吗?

input[type="email"] { animation: blink 1s step-start 0s infinite; }

I think to try to concatenate a variable through liquid and make the javascript call but it doesn't work for me either... Any tip? 我想尝试通过液体连接一个变量并进行javascript调用,但它对我来说也不起作用......任何提示?

Unfortunately to get what you want you'll need to compromise a bit and just give the illusion you're after. 不幸的是,得到你想要的东西,你需要妥协一点,只是给你想要的幻觉 Which may take a little tweaking per instance but you could use javascript to cheat and make it more generic but hopefully this example gives a decent starting place, cheers! 可能需要对每个实例进行一些调整,但你可以使用javascript作弊并使其更通用但希望这个例子给出了一个不错的起点,欢呼!

 let tempPlaceholder = ''; cleanUp = (me) => { const thePlaceHolder = me.parentElement; tempPlaceholder = thePlaceHolder.getAttribute('data-placeHolder'); thePlaceHolder.setAttribute('data-placeholder', ''); } putItBack = (me) => { if (!me.value) { const thePlaceHolder = me.parentElement; thePlaceHolder.setAttribute('data-placeholder', tempPlaceholder); tempPlaceholder = ''; } } 
 @keyframes typing { from { width: 0; } } @keyframes blink-caret { 50% { border-color: transparent; } } aside { position: relative; display: inline-block; height: 1.5rem; } aside:after { content: attr(data-placeholder); position: absolute; top: .25rem; left: .5rem; border-right: 1px solid #333; color: #555; width: 22em; /* IE fallback */ width: 16ch; white-space: nowrap; overflow: hidden; pointer-events: none; animation: typing 2s steps(22, end), blink-caret .5s step-end infinite alternate; } input { height: 1.25rem; width: 20rem; padding: 0 .5rem; } 
 <aside id="placeholder" data-placeholder="I am a placeholder..."> <input type="text" aria-labelledby="placeholder" onfocus="cleanUp(this)" onfocusout="putItBack(this)"> </aside> 

For some reason the input does not focus in the snippet, but this works OK in the browser 由于某种原因,输入不会集中在代码段中,但这在浏览器中可以正常工作

 var inpt = document.getElementById("inp"), dv = document.getElementById("dv"); inpt.focus(); inpt.onkeypress = dv.onclick = function() { dv.childNodes[0].nodeValue = ""; inpt.focus() } inpt.onkeyup = inpt.onblur = function() { if (inpt.value == "") { dv.childNodes[0].nodeValue = "Placeholder"; setTimeout(function() { inpt.focus(); }, 0) } } 
 #dv { display: inline-block; } #inp { position: relative; border: none; } 
 <div id="dv"> Placeholder <input id="inp"> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM