一个最简单的照片浏览器

岳谦
2023-12-01
作个最简单的简历网站,加了最少的照片,只好弄个最简单的照片浏览器。
本不好意思写出来,结果看到51js有人留言向参考,于是贴出来算了。

//button class 
var button = function(buttonId,buttonValue,index){
        var bt = document.createElement("input");
        bt.setAttribute("type","button");
        bt.setAttribute("id", buttonId);

        bt.setAttribute("value",buttonValue);
        bt.attachEvent("onclick", function(){controlImg(event, index)});
        return bt;
     }

//image control
function controlImg(event,index)
{
    if (index == 1)    
    {
        m_imgLocation = parseInt(document.getElementById("imgLocation").value);
        if (m_imgLocation <= minIndex) 
            m_imgLocation = maxIndex;
        else 
            m_imgLocation-=1;
 
        var img = document.getElementById("img1");
        if (null != img)
        {
            var divMain = document.getElementById("main");
            divMain.removeChild(img);
        }
            
        var img = document.createElement("img");
        img.setAttribute("id","img1");
        img.className = "photo";
        img.src ="pic_" + m_imgLocation + ".jpg";
        divMain.appendChild(img);
        document.getElementById("imgLocation").value = m_imgLocation;
    }
    else
    {
        m_imgLocation = parseInt(document.getElementById("imgLocation").value);
        if (m_imgLocation >= maxIndex) 
            m_imgLocation = minIndex;
        else 
            m_imgLocation+=1;
            
        var img = document.getElementById("img1");
        if (null != img)
        {
            var divMain = document.getElementById("main");
            divMain.removeChild(img);
        }
        var img = document.createElement("img");
        img.setAttribute("id","img1");
        img.className = "photo";
        img.src = "pic_" + m_imgLocation + ".jpg";
        divMain.appendChild(img);
        document.getElementById("imgLocation").value = m_imgLocation;
     }


function createImage()
{
            var img = document.createElement("img");
            img.setAttribute("id","img1");
            img.className = "photo";
            img.src = "pic_0.jpg";
            divTable.appendChild(img);
            var btnLast = new button("Last","<<","1");
            btnLast.className = "LastImg";
            var btnNext = new button("Next",">>","2");
            btnNext.className = "NextImg";

            var table = document.createElement("table");
            var tbody = document.createElement("tbody");
            table.appendChild(tbody);
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            tbody.rows[0].cells[0].appendChild(btnLast);
            tbody.rows[0].insertCell(1);
            tbody.rows[0].cells[1].appendChild(btnNext);
            divTable.appendChild(table);
}  

转载于:https://www.cnblogs.com/yangxd/archive/2007/11/20/965628.html

 类似资料: