• javascript进行百度换肤 和显示隐藏一个窗口的操作


    简单的运用javascript来进行百度换肤的操作

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>百度换肤</title>
        <style>
            *{
                padding:0;
                margin:0;
            }
            body{
                100%;
                background:url('../js/2.jpg') no-repeat   center 0;
                background-size:cover;//自适应屏幕大小
            }
            .box{
                100%;
                padding-top:40px;
                background-color: rgb(255,0,0,0.3);
                text-align: center;
            }
            .box img{
                100px;
            }
        </style>
    </head>
    <body>
    <div class="box">
        <img src="../js/2.jpg" alt="" id="pic1">
        <img src="../js/1.jpg" alt="" id="pic2">
        <img src="../js/3.jpg" alt="" id="pic3">
        <img src="../js/4.jpg" alt="" id="pic4">
        <img src="../js/5.jpg" alt="" id="pic5">
    </div>
    <script type="text/javascript">
        window.onload = function(){
            var oimg1 = document.getElementById('pic1');
            var oimg2 = document.getElementsByTagName('img')[1];//获取父类中的下标为1的元素
            var oimg3 = document.getElementById('pic3');
            var oimg4 = document.getElementsByTagName('img')[3];
            var oimg5 = document.getElementById('pic5');
            oimg1.onclick = function(){
                console.log(this); //this代表当前本身
                document.body.style.backgroundImage = "url(../js/2.jpg)";//设置你点击的时候的图片
                //下面是改变自己变大的同时让别的缩小
                this.style.width ='200px'; //设置这个js中的图片大小
                oimg2.style.width = '100px'; //动态的别的变大这个变小
                oimg3.style.width = '100px';
                oimg4.style.width = '100px';
                oimg5.style.width = '100px';
    
            }
            oimg2.onclick = function(){
                console.log(this);
                document.body.style.backgroundImage = "url('../js/1.jpg')";
                this.style.width = '200px';
                oimg1.style.width ='100px';
                oimg3.style.width = '100px';
                oimg4.style.width = '100px';
                oimg5.style.width = '100px';
    
            }
            oimg3.onclick = function(){
                console.log(this);
                // document.style.backgroundImage = "url('../js/3.jpg')";
                document.body.style.backgroundImage = "url(../js/3.jpg)";
                this.style.width = '200px';
                oimg1.style.width = '100px';
                oimg2.style.width = '100px';
                oimg4.style.width = '100px';
                oimg5.style.width = '100px';
    
            }
            oimg4 .onclick = function(){
                console.log(this);
                document.body.style.backgroundImage = "url(../js/4.jpg)";
                this.style.width = '300px';
                oimg1.style.width = '100px';
                oimg2.style.width = '100px';
                oimg3.style.width = '100px';
                oimg5.style.width = '100px';
            }
            oimg5.onclick = function(){
                document.body.style.backgroundImage = "url(../js/5.jpg)";
                this.style.width = '200px';
                oimg1.style.width = '100px';
                oimg2.style.width = '100px';
                oimg3.style.width = '100px';
                oimg4.style.width = '100px';
            }
            
        }
    </script>
    </body>
    </html>

    显示隐藏一个窗口界面:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>隐藏显示</title>
        <style>
            .show{
                height:200px;
                200px;
                background-color: red;
            }
        </style>
    </head>
    <body>
    <div class="box">
        <button>隐藏</button>
        <div class="show" id = 'heizi'></div>
    
    </div>
    <script>
        window.onload = function(){
            var heizi = document.getElementById('heizi');
            var isShow = true;
            document.getElementsByTagName('button')[0].onclick = function(){//先以第一个元素来进行判定
                console.log(this);
                if(isShow){
                    heizi.style.display = 'none';
                    this.innerText = '显示';
                    isShow = false;
                }else{
                    heizi.style.display = 'block';
                    this.innerText = '隐藏';
                    isShow = 'true';
                }
            }
        }
    </script>
    
    </body>
    </html>
    显示隐藏窗口界面
  • 相关阅读:
    实用JS代码
    javascript-table出现滚动条表格自动对齐
    Javascript-关于for in和forEach
    Javascript-关于break、continue、return语句
    如何编写可怕的Java代码?
    请停止编写这么多的for循环!
    如何优雅地在Stack Overflow提问?
    为什么阿里巴巴Java开发手册中强制要求不要在foreach循环里进行元素的remove和add操作?
    Java异常处理只有Try-Catch吗?
    看完这篇还不会用Git,那我就哭了!
  • 原文地址:https://www.cnblogs.com/zhaoyunlong/p/9107994.html
Copyright © 2020-2023  润新知