简体   繁体   English

输入slideUp / slideDown问题

[英]Input slideUp/slideDown issue

Seems like jQuery removes the value of a input fields that has been slided up and then afterwards down. 看起来像jQuery删除了已经滑动然后向下滑动的输入字段的值。 Not quite sure if it's the placeholder who does it but the built in slideUp/Down seems to bug the input field. 不太确定它是否是占位符,但是内置的slideUp / Down似乎会破坏输入字段。

Here is a example: http://jsfiddle.net/k3Bc2/ 这是一个例子: http//jsfiddle.net/k3Bc2/

$(document).ready(function () {
    $('#slideUp').click(function () {
        $('input[type="text"]').slideUp(1000);
    });

    $('#slideDown').click(function () {
        $('input[type="text"]').slideDown(1000);
    });
});

If you enter a value in the input field and click the slideUp button and wait till it's slided up and then click the slideDown you will see the value of the input field is missing. 如果在输入字段中输入一个值并单击slideUp按钮并等到它滑动,然后单击slideDown,您将看到缺少输入字段的值。

Does anyone know a workaround to get a slideUp/slideDown working on the example linked? 有没有人知道一个解决方法,以获得一个slideUp / slideDown工作链接的示例?
Using google chrome if that gives an idea of why. 使用谷歌浏览器如果能够了解原因。

Error occurs when height of the input comes 0. You should change your method. 输入高度为0时发生错误。您应该更改方法。 Use css position with masking animate method: 使用具有掩蔽动画方法的css位置:

Here is demo link. 这是演示链接。 You'll inspect there will be no bug with this method. 您将检查此方法是否存在任何错误。

jQuery: jQuery的:

$(document).ready(function () {
    $('#slideUp').click(function () {
        $('input[type="text"]').stop().animate({'top':'200px'},400);
    });

    $('#slideDown').click(function () {
        $('input[type="text"]').stop().animate({'top':'0px'},400);
    });
});​

html: HTML:

<div id="mask">
   <input id="motion" type="text" value="" placeholder="Enter some text.." />
</div>
<input type="button" value="slideUp" id="slideUp" />
<input type="button" value="slideDown" id="slideDown" />​

css: CSS:

#mask { position:relative; 160px; height:25px; overflow:hidden; top:0; left:0; }
#motion { position:absolute; top:0; left:0; }
input { position:relative; } ​

It seems like a bug in chrome (not jQuery). 这似乎是chrome(而不是jQuery)中的一个bug。 It works fine in ff. 它在ff中运行良好。

Its something related with font-size , I guess. 我想这与font-size有关。 Chrome does not loses font-size but if you set again, it works. Chrome不会丢失font-size但如果再次设置,则可以正常工作。

$(document).ready(function () {
    $('#slideUp').click(function () {
        $('input[type="text"]').slideUp(1000);
    });

    $('#slideDown').click(function () {
        $('input[type="text"]').slideDown(1000,function(){ 
             $(this).css('font-size',$(this).css('font-size'));                
        });
    });
});​

Demo 演示

EDIT: 编辑:

I see that above hack works for one time only. 我看到上面的hack只工作了一次。 If you slide up/down again, it fails. 如果再次向上/向下滑动,则会失败。

Here's a better hack. 这是一个更好的黑客。

.text{ 
    font-size:13px; 
}​

$(document).ready(function () {
    $('#slideUp').click(function () {
        $('input[type="text"]').slideUp(1000,function(){
               $(this).removeClass('text');        
        });
    });

    $('#slideDown').click(function () {
        $('input[type="text"]').slideDown(1000,function(){    
            $(this).addClass('text');     
        });
    });
});​

Demo 演示

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

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