Outils pour utilisateurs

Outils du site


devweb:jquery:agrandir_pre_hover (lu 21544 fois)

Agrandir div onMouseOver

function log(s) {
    if (window.console && window.console.log)
        window.console.log(s);
}
 
jQuery(document).ready (
    function () {
        // By default, <pre> should be styled "overflow: auto"
        // so as to degrade gracefully if Javascript is unavailable
        jQuery("pre").css({
                        zIndex: "100",
                        position: "relative",
                        overflow: "hidden"
                    })
 
        // We could precalculate the widths and store them in the <pre> object
        // but browser font size change would invalidate them and there is
        // no builtin onfontsizechange event in Javascript. 
        // (It is possible to simulate it, but that would create more overhead.)
        jQuery("pre").hover(
            function() {
                var desiredWidth = 0;
                jQuery(this).children().each(function() {
                    var w = jQuery(this).width()
                    log("this.width = "+w)
                    if (w > desiredWidth) desiredWidth = w
                });
                log(desiredWidth);
 
//                var desiredWidth = jQuery("code", this).width() + 10;
                if (!this.resetToWidth) {
                    this.resetToWidth = jQuery(this).width();
                }
                if (desiredWidth > this.resetToWidth) {
                    jQuery(this)
                        .stop(true, false)
                        .animate({
                            width: desiredWidth + "px"
                        });
                }
            }, 
            function() {
                jQuery(this).stop(true, false).animate({
                    width: this.resetToWidth + "px"
                });
            }
        );
    }
);

Vu ici ⇒ http://blog.dmitryleskov.com/small-hacks/pushing-files-from-windows-to-linuxunix-hosts-with-cwrsync/

devweb/jquery/agrandir_pre_hover.txt · Dernière modification: 23-06-2013 18:05 de edmc73