鼠标移上去变大、改变背景颜色等

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <style type="text/css">
        *{
            margin: 0px auto;
            padding: 0px;
        }
        
        #anniu{
            width:100px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: blue;
        }
        #anniu2{
            width:100px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: blue;
        }
        #anniu3{
            width:100px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: blue;
            
        }
        #anniu4{
            width:100px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: blue;
            display: none;
        }
        #continer{
            width:100%;
            height: 200px;        
            background-color: red;
            
            }
        #anniu5{
            width:100px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: blue;
            }
        #anniu6{
            width:100px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: blue;
            display: none;
            float:left;
     }
        
        
    </style>
    <body>
        <div id="anniu" οnclick="tanChuang()">按钮</div>
        <input type="button" name="" id="anniu2" value="按钮" οnclick="tanChuang()"/>
        <button id=anniu3 οnclick="tanChuang()">按钮</button>
            <br />    <br />
        <label οnmοuseοver="xianshi()" οnmοuseοut="yincang()"><input type="checkbox" />鼠标经过出现按钮</label>
        <button id="anniu4">按钮</button>
        <br />    <br />
        <div id="continer" οnmοuseοver="yiRu()" οnmοuseοut="yichu()">鼠标经过这个div变高变色,移出再恢复</div>
        <div id="anniu3" οnclick="change1()">颜色1 </div>
        <br />    <br />
        <div id="anniu3" οnclick="change2()">颜色2 </div>    
        <br />    <br />
        <br />    <br />
        <button id="anniu5" οnclick="showhide()">按钮1</button>
        <button id="anniu6" οnclick="showhide()">按钮2</button>
    </body>
</html>
<script type="text/javascript">
    function tanChuang() {
        alert("弹出窗口");
    }    
    function xianshi(){
        var div1 =document.getElementById("anniu4");
        div1.style.display="block";
    }
    function yincang(){
        var div1 =document.getElementById("anniu4");
        div1.style.display="none";
    }
    function yiRu(){
        var div2=document.getElementById("continer");
        div2.style.width = "80%";
        div2.style.height = "400px";
        div2.style.backgroundColor ="green"
    }
    function yichu(){
        var div2=document.getElementById("continer");
        div2.style.width = "100%";
        div2.style.height = "200px";
        div2.style.backgroundColor ="red "
    }
    function change1(){
        var bodycolor=document.body;
        bodycolor.style.backgroundColor="red";
    }
    function change2(){
        var bodycolor=document.body;
        bodycolor.style.backgroundColor="green";
    }
    function showhide(){
        var showhide = document .getElementById("anniu6").style.display;
        if(showhide=='none'){
            document .getElementById("anniu6").style.display="block";
        }else{
            document .getElementById("anniu6").style.display="none";
        }
    }

    </script>

 

转载于:https://www.cnblogs.com/zhengleilei/p/9062268.html

第01个小程序:随鼠标移动而变色的背景(VaryTheBackground.cs) 程序运行时,当鼠标指针靠近窗口中心程度不同,客户区的背景颜色也不同。 using System; using System.Windows; using System.Windows.Input; using System.Windows.Media; namespace Chapter02 { public class VaryTheBackground : Window { SolidColorBrush brush = new SolidColorBrush(Colors.Black); //创建画刷 。SolidColorBrush是最简单的画刷。 [STAThread] public static void Main() { Application app = new Application(); app.Run(new VaryTheBackground()); } public VaryTheBackground() { Title = "Vary the Background"; Width = 384; Height = 384; Background = brush; } //鼠标移动事件 protected override void OnMouseMove(MouseEventArgs args) { //窗口呈现尺寸-边框和标题栏的尺寸 double width = ActualWidth - 2 * SystemParameters.ResizeFrameVerticalBorderWidth; double height = ActualHeight - 2 * SystemParameters.ResizeFrameHorizontalBorderHeight - SystemParameters.CaptionHeight; Point ptMouse = args.GetPosition(this); //获取鼠标位置 Point ptCenter = new Point(width / 2, height / 2); //窗口中心 Vector vectMouse = ptMouse - ptCenter; //向量。向:中心指向鼠标位置;量:鼠标位置与中心距离 double angle = Math.Atan2(vectMouse.Y, vectMouse.X); Vector vectEllipse = new Vector(width/ 2 * Math.Cos(angle), height / 2 * Math.Sin(angle)); Byte byLevel = (byte)(255 * (1 - Math.Min(1, vectMouse.Length / vectEllipse.Length))); Color clr = brush.Color; clr.R = clr.G = clr.B = byLevel; brush.Color = clr; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值