jquery - 使用 JQuery 淡入/淡出文本框中的文本并修复 CSS 中的按钮

标签 jquery html css

问题 #1:如何淡入淡出文本而不是仅在文本框中显示文本

问题 #2 [已解决]:我想在按钮图标和文本之间留一些空间,但它不起作用。 按钮示例:

image overlapping texts

更新: padding-left: 30px; 修复了空间问题。

html:

<input type="button" id="sv" value="          Score Viewer"></input>
<input type="button" id="pv" value="          Print Viewer"></input>
<input type="button" id="ev" value="          Exam Viewer"></input>
<br>
<input type=text id="tvinfo" value="" readonly size=50 />

JQuery:

$(function() {
    $('#sv').hover(
        function () {
            $('#tvinfo').val("View scores of exams already taken");
        }, 
        function () {
            $('#tvinfo').val("");
        }
    );
    $('#pv').hover(
        function () {
            $('#tvinfo').val("View who printed the certificate");
        }, 
        function () {
            $('#tvinfo').val("");
        }
    );
    $('#ev').hover(
        function () {
            $('#tvinfo').val("View who already took the exam");
        }, 
        function () {
            $('#tvinfo').val("");
        }
    );
});

CSS:

#sv {
    background: #ccc url(view.png) no-repeat top left;
    height: 53px;
    width: 186;
    cursor: pointer;
}
#pv {
    background: #ccc url(print.png) no-repeat top left;
    height: 53px;
    width: 186;
    cursor: pointer;
}
#ev {
    background: #ccc url(taken.png) no-repeat top left;
    height: 53px;
    width: 186;
    cursor: pointer;
}

最佳答案

查看此演示 http://jsfiddle.net/yeyene/tfRed/像那样?

我刚刚创建了一个假输入框并淡入/淡出实际输入框的不透明度,并使用 .stop() 来更快地悬停/悬停。

$(function() {
    $('#sv').hover(
        function () {
            $('#tvinfo').stop().fadeTo(500,1).val("View scores of exams already taken");
        }, 
        function () {
            $('#tvinfo').stop().fadeTo(200,0, function() {$(this).val("");});
        }
    );
    $('#pv').hover(
        function () {
            $('#tvinfo').stop().fadeTo(500,1).val("View who printed the certificate");
        }, 
        function () {
            $('#tvinfo').stop().fadeTo(200,0, function() {$(this).val("");});
        }
    );
    $('#ev').hover(
        function () {
            $('#tvinfo').stop().fadeTo(500,1).val("View who already took the exam");
        }, 
        function () {
            $('#tvinfo').stop().fadeTo(200,0, function() {$(this).val("");});
        }
    );
});

关于jquery - 使用 JQuery 淡入/淡出文本框中的文本并修复 CSS 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17454145/

相关文章:

javascript - 对于唯一的 dom 元素总是使用 live() 而不是 bind() 的缺点?

javascript - 语法错误: missing ) after argument list var x = $ ("input[name="+value +'[]' "]")

javascript - Chrome 无法在重复的标签上播放 html5 视频

html - 包含 div 的 float li 不起作用

CSS变换。如何从 "matrix( 0, 1, -1, 0, 0, 0"获取旋转 Angular 值)?

javascript - 拒绝在 jQuery ajax 中延迟

c# - 如何在C#中反序列化json对象

html - 奇怪的 :hover bug with z-index and img

html css 什么是现代线?

html - css 'content' 功能未显示