js右鍵菜單和右下角彈窗

幾個js常常用到的功能,整理一下javascript

1右鍵快捷菜單java

  
  
  
  
  1. <script type="text/javascript"> 
  2.        //右鍵點擊  
  3.        document.oncontextmenu = function()  
  4.        {  
  5.              showMenu();  
  6.                return false;//屏蔽掉的右鍵菜單  
  7.        }  
  8.        function  showMenu()  
  9.        {  
  10.              popMenu(itemMenu,100 );  
  11.                  //禁用右鍵  
  12.                  event.returnValue=false;  
  13.                  //不上傳事件  
  14.                  event.cancelBubble=true;  
  15.                  return false;  
  16.        }  
  17.         //menuDiv:右鍵菜單的內容  
  18.         //width:行顯示的寬度  
  19.         function popMenu(menuDiv,width ){  
  20.           //建立彈出菜單  
  21.           var pop=window.createPopup();  
  22.           //設置彈出菜單的內容  
  23.           pop.document.body.innerHTML=menuDiv .innerHTML;  
  24.           var rowObjs=pop.document.body.all[0].rows;  
  25.           //得到彈出菜單的行數  
  26.           var rowCount=rowObjs.length;  
  27.           //設置鼠標滑入該行時的效果  
  28.             for(var i=0;i<rowObjs.length;i++)  
  29.              {  
  30.               rowObjs[i].cells[0].onmouseover=function (){  
  31.                this.style.background="#cccccc";  
  32.                this.style.color="black";  
  33.                }  
  34.                 rowObjs[i].cells[0].onmouseout=function (){  
  35.                this.style.background="#ff6666";  
  36.                  
  37.                }  
  38.              }  
  39.            
  40.            //屏蔽菜單的菜單  
  41.            pop.document.oncontextmenu=function (){  
  42.            return false;  
  43.            }  
  44.            //選擇右鍵菜單的一項後,菜單隱藏  
  45.            pop.document.onclick=function (){  
  46.            pop.hide();  
  47.            }  
  48.            //顯示菜單  
  49.            pop.show(event.clientX-1,event.clientY,width, rowCount*50,document.body);  
  50.            return true;  
  51.        }  
  52.     </script> 
  53.  
  54. <div id="itemMenu" style="display: none">
            <table border="1" width="100%" height="100%" bgcolor="#ff6666" style="border: thin"
                cellspacing="0">
                <tr>
                    <td style="cursor: default; border: outset 1;" align="center" onclick="parent.create(1)">
                        <img src="Jos的下午茶/coffee.ico" alt="下午茶" />
                    </td>
                </tr>
                <tr>
                    <td style="cursor: default; border: outset 1;" align="center" onclick="parent.create()">
                        <img src="Jos的下午茶/咖啡杯.ico" alt="下午茶" />
                    </td>
                </tr>
                <tr>
                    <td style="cursor: default; border: outset 1;" align="center" onclick="parent.create(3)">
                        <img src="Jos的下午茶/甜甜圈.ico" alt="下午茶" />
                    </td>
                </tr>
            </table>
        </div>

2右下角彈出框ide

  
  
  
  
  1. <script language="JavaScript" type="text/javascript">   
  2.       
  3.     function $(obj){   
  4.         return document.getElementById(obj);   
  5.     }   
  6.     function pop(obj){   
  7.         var h = parseInt($("popDiv").currentStyle.height);   
  8.         $("popDiv").style.height = (h + obj) + "px";   
  9.         if(parseInt($("popDiv").style.height) < 2)  
  10.         {   
  11.             window.clearInterval(timer);   
  12.             $("popDiv").style.display = "none";   
  13.         }   
  14.         if(parseInt($("popDiv").style.height) >= 200){   
  15.             window.clearInterval(timer);   
  16.         }   
  17.    
  18.     }   
  19.        
  20.     var timer;   
  21.     function runtimer(obj){   
  22.         timer = window.setInterval(function(){pop(obj)},10);   
  23.     }   
  24.     window.onload = function(){   
  25.         runtimer(2);   
  26.     }  
  27.     //每隔10秒調用show方法,若是顯示則隱藏,若是隱藏則顯示   
  28.      setInterval(  show ,10000 );   
  29.       function show(){  
  30.       if (  $("popDiv").style.display == "none" )  
  31.       {  
  32.       $("popDiv").style.display = "inline"   
  33.         runtimer(2);  
  34.            
  35.       }   
  36.       else  
  37.       {  
  38.           runtimer(-2);  
  39.       }  
  40.          
  41.      }  
  42. </script> 
  43. <div style="position:absolute;right:0;bottom:0;height:0px;width:200px;border:1px solid red;" id="popDiv">    
              <table>
                 <tr>
                   <td>
                        <a href="javascript:runtimer(-2);void(0)" >工做提示</a> //點擊則彈出框關閉
                   </td>
                 </tr>
              </table>
            </div> 

3向上滾動數據this

  
  
  
  
  1. <script   type="text/javascript"> 
  2.     var speed=40;//數值越大,速度越慢  
  3.     var demo2=document.getElementById("demo2");  
  4.     var demo1=document.getElementById("demo1");  
  5.     var demo=document.getElementById("demo");  
  6.     demo2.innerHTML=demo1.innerHTML;  
  7.     demodemo.scrollTop=demo.scrollHeight;  
  8.     function MarqueeUp(){  
  9.     if(demo2.offsetTop-demo.scrollTop<=0)  
  10.     demo.scrollTop-=demo2.offsetHeight;  
  11.     else{  
  12.     demo.scrollTop++;  
  13.     }  
  14.     }  
  15.     var MyMar=setInterval(MarqueeUp,speed);  
  16.     demo.onmouseover=function() {clearInterval(MyMar);}  
  17.     demo.onmouseout=function() {MyMar=setInterval(MarqueeUp,speed);}  
  18. </script>  

  19. <div id="demo" style="overflow:hidden;height:100px;width:210px; border:1px solid #666;">
    <div id="demo1">
     
    <p>這個向上滾動的文字特效JS代碼比較簡潔 。</p>
    <p>這個向上滾動的文字特效JS代碼比較簡潔 。</p>
    <p>這個向上滾動的文字特效JS代碼比較簡潔 。</p>
    <p>這個向上滾動的文字特效JS代碼比較簡潔 。</p>
    </div>
  20. <div id="demo2"></div></div>
相關文章
相關標籤/搜索