开发者

Is there a jQuery plugin for fading textbox hints?

I was wondering whether there is a jQuery plugin available which can show hints in a textbox when it is empty.

What I found was: http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/. However, this just acts as the placeholder HTML5 attribute. What I'm looking for开发者_高级运维 is rather a plugin that shows multiple hints with fading, as on http://www.wolframalpha.com/. (Edit: I mean the grey text in the textbox - not the tooltip.)

Although it might not be too much trouble to create it myself, I don't subscribe to the theory of reinventing the wheel - so does anyone know if such a plugin is already available?

Thanks.


I made one up myself, so that it fits my needs completely: http://jsfiddle.net/42t6R/2/.

It's simple but it works just nicely.

Edit: New version which has less bugs, also why not submit it as a plugin :)

http://plugins.jquery.com/project/fadehints

http://jsfiddle.net/9rgHg/2/

(function( $, undefined ) {

    $.fn.fadehints = function( data, speed ) {
        var i = 0;
        var $this = $( this );
        var offset = $this.offset();
        var $input = $("<input>").css( "position",          "absolute"                 )
                                 .css( "left",              offset.left                )
                                 .css( "top",               offset.top                 )
                                 .css( "background-color",  "transparent"              )
                                 .css( "color",             "gray"                     )
                                 .css( "border",            0                          )
                                 .css( "padding",           2                          )
                                 .css( "font-size",         $this.css( "font-size"   ) )
                                 .css( "font-family",       $this.css( "font-family" ) );

        var $parent = $this.parent();
        var $div = $( "<div>" ).append( $this.detach(), $input );

        var change = function() {
            if( i >= data.length ) {
                i = 0;
            }
            $input.hide().val( data[i] ).fadeIn( 1000 );
            i++;
        };

        $this.bind( "focus keydown", function(e) {
            if( !( e.bubbles == null ) ) { // Only clear if event was triggered by user
                window.clearInterval( interval );
                $input.hide();
            }
        } );

        $input.bind( "click focus", function() {
            window.clearInterval( interval );
            $this.focus(); // $this === the real textbox
            $( this ).hide(); // $(this) === the overlap textbox
        } );

        $this.click( function() {
            $input.hide();
            window.clearInterval( interval );
        } );

        $this.blur( function() {
            window.clearInterval( interval );
            if( $this.val() === "" && $this[0] !== document.activeElement ) {
                if( !$input.is(":visible")) {
                change();
                }
                interval = window.setInterval( change, speed );
            }
        } );
        $parent.append( $div );

        change(true);
        var interval = window.setInterval( change, speed );


        return $this;
    };

})(jQuery);

$(function() {
    $('#tb').fadehints([
        "test1", "test2"
    ]);
});


This may help: http://www.webdesignbooth.com/15-jquery-plugins-to-create-an-user-friendly-tooltip/


Hey there primvdb, what about this?


Try this : http://jqueryfordesigners.com/coda-popup-bubbles/ It should be what you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜