0

我必须在很短的时间内显示图像,50 毫秒(这是用于第一印象测试),但是每次用户单击按钮时通过设置 src 来切换图像会产生太大的延迟。这是代码:

HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Studio usabilità</title>
        <link rel="stylesheet" href="style.css" > 
        <script type="text/javascript" src="myscripts.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="action_panel">
                <div class="label">
                    ISTRUZIONI: Nell'istante in cui si clicca su un bottone, viene aperta la pagina corrispondente
                    nello spazio bianco sotto questa sezione. L'immagine verrà visualizzata per un tempo molto breve.
                </div>
                <button class="button" id='btn1' onclick='javascript:changeImage("prova.jpg","btn1","false");'>PROVA</button>
                <button class="button" id='btn2' onclick='javascript:changeImage("sito1.jpg","btn2","true");'>SITO #1</button>
                <button class="button" id='btn3' onclick='javascript:changeImage("sito2.jpg","btn3","true");'>SITO #2</button>
            </div>
            <img src="" class="image" id="image" alt=""/>
        </div>
    </body>
</html>

CSS:

root { 
display: block;
}

body, html { /* set size of body to full page and remove margins */
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

.action_panel {
    margin: auto;
    text-align: center;
    position: absolute; 
    height: 40px; 
    width: 100%; 
    background-color: darkslategrey;
}

.button {
    float: left;
    margin-top: 6px;
    margin-left: 10px;
    width:100px;
    height: 28px;
    background-color:activecaption;
}

.image {
    margin-top: 40px;
    margin-left: 300px;
    height: 600px;
    display: none;
}

.label {
    width: 850px;
    float: left;
    color: gainsboro;
    margin-left: 40px;
    margin-right: 40px;
    text-align: left;
}

JAVASCRIPT:

function changeImage(img, btn, disable) {
    var obj = document.getElementById('image');
    obj.src = img;
    obj.style.display = 'inline';
    setTimeout(
        function() {
            obj.style.display = 'none'
        }, 50);
    this.disabled = 'disabled';
    if (disable == "true")
        document.getElementById(btn).disabled = 'true';
}
4

1 回答 1

0

您还可以保留三个图像并设置更改其显示,如您所说,每 50 毫秒,通过使用

obj.style.display = "none"

您无需在每次单击按钮时保留单个图像元素并更改其 src。

于 2013-05-01T08:24:29.040 回答