一个最简单的照片浏览器

作个最简单的简历网站,加了最少的照片,只好弄个最简单的照片浏览器。
本不好意思写出来,结果看到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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值