再点击jQuery(Second click jQuery)

我试图制作一个动画,当我点击一个搜索图标时,它会淡入搜索输入并添加一个类以使其更宽。 问题是我不知道在搜索输入已经显示之后如何在第二次点击时使其变为fadeOut:

这是我的代码:

    $('#menu_search').click(function(){
        $('.search_input').fadeIn().toggleClass('full');
    });


    <li id="menu_search">
        <a href="javascript:void(0)"></a>
        <div class="search_input_container">
            <input type="text" class="search_input" value="Buscar">
        </div>
    </li>


        &#menu_search{
            background: url('../img/sprites.png') #000 2px 2px;
            width: 34px;
            height: 28px;
            padding: 0;
            margin-right: 0;
            a{
                display: inline-block;
                width: 100%;
                height: 100%;
            }
            .search_input_container{
                width: 500px;
                height: 30px;
                position: absolute;
                z-index: 20;
                left: -466px;
                .search_input{
                    float: right;
                    width: 100px;
                    background: #ffffff;
                    height: 30px;
                    border: none;
                    .round_corners();
                    .animate();
                    display: none;
                    &.full{
                        width: 772px;
                        display: block;
                    }
                }
            }
        }

I´m trying to make an animation that when I click on a search icon, it fadeIn the search input and add a class to make it wider. The problem is that I don´t know how to make it fadeOut in the second click after the search input it´s already displayed:

this is my code:

    $('#menu_search').click(function(){
        $('.search_input').fadeIn().toggleClass('full');
    });


    <li id="menu_search">
        <a href="javascript:void(0)"></a>
        <div class="search_input_container">
            <input type="text" class="search_input" value="Buscar">
        </div>
    </li>


        &#menu_search{
            background: url('../img/sprites.png') #000 2px 2px;
            width: 34px;
            height: 28px;
            padding: 0;
            margin-right: 0;
            a{
                display: inline-block;
                width: 100%;
                height: 100%;
            }
            .search_input_container{
                width: 500px;
                height: 30px;
                position: absolute;
                z-index: 20;
                left: -466px;
                .search_input{
                    float: right;
                    width: 100px;
                    background: #ffffff;
                    height: 30px;
                    border: none;
                    .round_corners();
                    .animate();
                    display: none;
                    &.full{
                        width: 772px;
                        display: block;
                    }
                }
            }
        }

原文:https://stackoverflow.com/questions/15269581
2024-04-22 16:04

满意答案

你需要一个中间char数组来打印strcat前的数字,或者你可以直接将数字rv ,但是为此你需要一个指向结尾的指针,

char *rv = malloc(2048);
char *rv_end = rv;
...
rv_end += sprintf(rv_end, "%d", fib(num));

并在将其他内容附加到缓冲区时更新rv_end指针。

(感谢jthill使用sprintf的返回值进行改进。)


You need either an intermediate char array to print the number to before strcating, or you can directly sprintf the number to rv, but for that you need a pointer to the end,

char *rv = malloc(2048);
char *rv_end = rv;
...
rv_end += sprintf(rv_end, "%d", fib(num));

and also update the rv_end pointer when appending other things to the buffer.

(Thanks to jthill for the improvement using the return value of sprintf.)

相关问答

更多

在C中使用strcat(Using strcat in C)

更改 char *message = "\n\nHTTP/1.1 "; 至 char message[1024]; strcpy(message,"\n\nHTTP/1.1 "); 你应该没问题,总共消息长度为1023。 编辑:(根据mjy的评论)。 以这种方式使用strcat是获得缓冲区溢出的好方法。 您可以随时编写一个检查缓冲区大小和传入字符串添加长度的小函数来克服此问题,或者在动态缓冲区上使用realloc。 国际海事组织,负责程序员检查使用正确的缓冲区大小,如sprintf和其他C...

strcat C不打印,int为char *(strcat C not printing and int to char*)

不,它没有“正确”地做到这一点; 你的代码非常破碎。 编译器在发出警告时并不是很有趣,他们通常知道他们在说什么,而是你需要弄清楚你的代码有什么问题导致它触发警告。 因为应该没有。 在您的情况下,此代码例如: char *session = (char*) ( rand() % (9999 - 1000 + 1) + 1000 ); 无效,并且使用session就像它指向有效字符串一样,很可能会调用未定义的行为。 您不能将事物“转换”为C中的字符串,除非它们是以0开头的字节数组,用于描述预期编码中...

C函数使用strcat和字符串(C function using strcat with strings)

您没有分配空间来保存输入字符串的两个副本。 strcpy复制字符串。 strcat将一个字符串附加到另一个字符串。 malloc在堆上分配应该是free()字节。 char *two(char *foo); int main() { char * ptr = two("foo"); printf("The value of two(\"foo\") is %s", ptr); free(ptr); } char *two(char *foo) { char *...

如何使用strcat()函数?(How to use strcat() function?)

在C语言中,函数strcat不会创建包含连接字符串的新字符数组。 它将第二个字符串中的字符附加到第一个字符数组的第一个字符串,前提是它有足够的元素来存储新字符。 否则,该函数将尝试覆盖导致未定义行为的字符数组之外的内存。 因此,在第一个程序中有效使用该函数可以采用以下方式 #include <stdio.h> #include <string.h> int main(int argc, const char *argv[]) { char s1[11] = "12345"; ch...

strcat用char指向字符串文字(strcat with char pointer to a string literal)

如果我理解你的问题是正确的,你会发现程序有未定义的行为,因为无法保存字符串“Solaris”与“Linux”连接。 所以你要找的答案不是“这是未定义的行为”,而是: 它为什么会这样 在处理未定义的行为时,我们无法对正在发生的事情做出一般性解释。 对于不同的编译器(或编译器版本)等,它可能在不同的系统上执行不同的操作或执行不同的操作。 因此,人们经常说,尝试解释具有未定义行为的程序中发生的事情是没有意义的。 好吧 - 这是正确的。 但是 - 有时你可以找到适合你的特定系统的解释 - 只要记住它是特定...

用字符串和int使用strcat()的最有效方法是什么?(Most efficient way to use strcat() with a string and int?)

你需要一个中间char数组来打印strcat前的数字,或者你可以直接将数字rv ,但是为此你需要一个指向结尾的指针, char *rv = malloc(2048); char *rv_end = rv; ... rv_end += sprintf(rv_end, "%d", fib(num)); 并在将其他内容附加到缓冲区时更新rv_end指针。 (感谢jthill使用sprintf的返回值进行改进。) You need either an intermediate char array to...

strcat溢出?(strcat overflow?)

strcat()将一个字符串中的字符附加到另一个字符串。 目标字符串已修改。 所以strcat(str1, str2)修改str1也包含str2的内容。 由于没有为str1分配足够的内存来包含两个字符串中的字符,因此会导致溢出。 strcat() appends the characters from one string to another string. The target string is modified. So strcat(str1, str2) modifies str1 to...

strcat后自由分配的字符串(Free allocated string after strcat)

您没有为生成的连接字符串分配足够的空间; 当您在结束时写入时,您将调用未定义的行为(在这种情况下,可能是堆损坏)。 更改malloc以分配strlen(argv[2]) + strlen(".txt") + 1这样你就有了足够大的缓冲区来保存整个字符串。 You didn't allocate enough space for the resulting concatenated string; when you write past the end you invoke undefined be...

这个简单的代码使用字符串,malloc和strcat有什么问题?(What's wrong with this simple code using strings, malloc and strcat?)

您的代码通过写入只读存储并尝试写入其末尾来展示未定义的行为。 您的malloc理念是朝着正确方向迈出的一步。 但是,您应该使用strcpy将"Hello"复制到新分配的内存中。 此外,您需要考虑计划追加的字符串的大小,以及计算动态分配大小时的空终止符。 显然,您还需要在程序结束时释放所有已分配的内存: char** nameList; nameList = malloc(4*sizeof(char*)); nameList[0] = malloc(12); strcpy(nameList[0], ...

strcat的错误(Errors with strcat)

你将字符文字(包装在' )作为第二个参数传递给某些strcat strcat(group[leftIndex],'_'); 但是strcat期望第二个参数(以及它的第一个参数)是char*类型,而不是char ,它们都需要以NUL终止。 这就是投诉人抱怨的原因。 使用字符串文字而不是字符文字来解决问题: strcat(group[leftIndex],"_"); memset(group[i], 0, 256 + 1); 有一个错误。 使用 memset(group[i], 0, 256);...

相关文章

更多

jQuery点击滑过左则菜单

用jquery框架制作两种非常简单的jquery垂直手风琴菜单特效,鼠标滑过手风琴与鼠标点击触发手风琴 ...

jquery 问题

[color=green] [size=medium][size=small][size=medium ...

jquery 插件开发

jQuery插件的开发两种形式: 类级别的插件开发:即给jQuery添加新的全局函数,相当于给jQue ...

jquery与servlet交互的json问题

框架用烦了,目前只用servlet和jquery,servlet返回json数据,jquery在前面无 ...

Jquery 的IFame ready 问题?

我的代码如下 http://www.w3.org/TR/html4/strict.dtd&quot; ...

jQuery表格插件jqGrid(jquery.jqGrid.js)

jqGrid 是一个用来显示网格数据的jQuery插件,文档比较全面,附带中文版本,支持分页、滚动加载 ...

Jquery EasyUI系列教程4

EasyUI简单的Tree的一个小例子

解决点击没有内容的空白div没有响应click事件的方法

给一个div绑定一个click事件,如果这个div没有内容,在一般浏览器下都没有问题,在IE8下点击的 ...

jquery可编辑表格

jquery表格特效制作jquery可编辑表格,可对表格中的值进行编辑,鼠标离开后即可完成编辑,是一种 ...

jQuery中$与$()的区别?

jQuery中$与$()的区别?

最新问答

更多

python的访问器方法有哪些

使用方法: class A(object): def foo(self,x): #类实例方法 print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): #类方法 print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): #静态方法 print "executing static_foo(%s)"%x调用方法: a =

使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)

我认为你必须将两个TableGetway传递给UserTable构造。 你必须改变Module.php看看: public function getServiceConfig() { return array( 'factories' => array( 'User\Model\UserTable' => function($sm) { $userTableGateway = $sm->get('UserTable

透明度错误IE11(Transparency bug IE11)

这是一个渲染错误,由使用透明度触发,使用bootstrap用于在聚焦控件周围放置蓝色光环的box-shadow属性。 可以通过添加以下类覆盖来解决它。 .form-control:hover { -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); box-shadow: 0px 0px 4px 0px rgba(0,0,255,1)

linux的基本操作命令。。。

ls 显示目录 mkdir 建立目录 cd 进入目录

响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)

将z-index设置为.main-nav这将解决您的重叠问题 .main-nav { position:relative; z-index:9; } set z-index to .main-nav This will fix your overlaping issue .main-nav { position:relative; z-index:9; }

在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)

这是因为模式规范"a"打开一个文件以便追加,文件指针在末尾。 如果您尝试从此处读取,则由于文件指针位于EOF,因此没有数据。 您应该打开"r+"进行阅读和写作。 如果在写入之前读取整个文件,则在写入更多数据时,文件指针将正确定位以追加。 如果这还不够,请探索ftell()和fseek()函数。 That is because the mode spec "a" opens a file for appending, with the file pointer at the end. If you

NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)

支持空中接口的数据速率是一回事。 在消除协议开销,等待eeprom写入以及所有需要时间的其他内容之后,您看到的数据速率是完全不同的故事。 长话短说,从标签读取或进行对等传输时的实际数据速率峰值约为2.5千字节/秒。 取决于具体的标签或对等技术,它可能比这慢很多。 The supported data-rates of the air-interface are one thing. The data-rate that you see after removing protocol overhe

元素上的盒子阴影行为(box-shadow behaviour on elements)

它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂

Laravel检查是否存在记录(Laravel Checking If a Record Exists)

这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found

设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)

$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640