zoukankan      html  css  js  c++  java
  • jQuery中有关mouse的事件--mousedown/up/enter/leave/over/out----2017-05-10

    mousedown:鼠标按下才发生

    mouseup:鼠标按下松开时才发生

    mouseenter和mouseleave效果和mouseover mouseout效果差不多;但存在区别,区别见代码解析:

    css代码:

    <style>
                .cc,.dd{
                    height: 80px;
                    width: 300px;
                    border: 1px solid black;
                }
                .ff,.ee{
                    height: 200px;
                    width: 300px;
                    background-color: darkgrey;
                    border:1px solid red;
                    text-align: center;    
                }
            </style>

    html代码:

    <body>
    		
    		<div class="aa">1、please press down your mouse button</div><br />
    		<div class="bb">2、please press up your mouse button</div><br />
    		
    		<div class="cc"> 
    		
    			3、mouseenter:颜色变红
    			mouseleave:颜色变灰
    		
    		</div><br />
    		
    		<div class="dd"> 
    			4、mouseover:颜色变黄
    			mouseout:颜色变灰
    		</div><br />
    		
    		<div class="ff"> 5、<p style="background-color: white;">mouseout事件在鼠标离开任意一个子元素及选的元素时触发</p><span></span> </div><br />
    		<div class="ee"> 6、<p style="background-color: white;">mouseleave事件只在鼠标离开选取的的元素时触发。</p><span></span>  </div>	
    	</body>
    

      

    jqery代码:

    <script>
    //当鼠标按下时会显示
            $(".aa").mousedown(function(){
                $(this).after("<p>when mouse button press down</p>")
            });
    //当鼠标按下松开时发生的        
            $(".bb").mouseup(function(){
                $(this).after("<p>when mouse button press up</p>")
            });
    //当鼠标enter/leave
            $(".cc").mouseenter(function(){
                $(".cc").css("background-color","red")          
            });
             $(".cc").mouseleave(function(){
                $(".cc").css("background-color","grey")          
            });    
     //当鼠标mouseover/mouseout
           $(".dd").mouseover(function(){
               $(".dd").css("background-color","yellow")
           });
           $(".dd").mouseout(function(){
               $(".dd").css("background-color","grey")
           });
     //mouseleave 与 mouseout 的区别   
     x=0;
     y=0;
     $(".ff").mouseout(function(){
         $(".ff span").text(x+=1);
     })
     $(".ee").mouseleave(function(){
         $(".ee span").text(y+=1);
     })
     //mouseenter,mouseover同理
     //mouseover 事件在鼠标移动到选取的元素及其子元素上时触发 。
    //mouseenter 事件只在鼠标移动到选取的元素上时触发。
    </script>
  • 相关阅读:
    python 读写XLS
    python去噪算法
    编译freetype 的dll
    python生成测试图片
    python 将pdf分页后插入至word中
    ie height
    Formview单文档或对话框项目接受不到按键消息的解决办法
    SQL SERVER配置[转]
    PyQt5 布局
    PyQt5 各种菜单实现
  • 原文地址:https://www.cnblogs.com/chenguanai/p/6834708.html
Copyright © 2011-2022 走看看