幾個js常常用到的功能,整理一下javascript
1右鍵快捷菜單java
- <script type="text/javascript">
- //右鍵點擊
- document.oncontextmenu = function()
- {
- showMenu();
- return false;//屏蔽掉的右鍵菜單
- }
- function showMenu()
- {
- popMenu(itemMenu,100 );
- //禁用右鍵
- event.returnValue=false;
- //不上傳事件
- event.cancelBubble=true;
- return false;
- }
- //menuDiv:右鍵菜單的內容
- //width:行顯示的寬度
- function popMenu(menuDiv,width ){
- //建立彈出菜單
- var pop=window.createPopup();
- //設置彈出菜單的內容
- pop.document.body.innerHTML=menuDiv .innerHTML;
- var rowObjs=pop.document.body.all[0].rows;
- //得到彈出菜單的行數
- var rowCount=rowObjs.length;
- //設置鼠標滑入該行時的效果
- for(var i=0;i<rowObjs.length;i++)
- {
- rowObjs[i].cells[0].onmouseover=function (){
- this.style.background="#cccccc";
- this.style.color="black";
- }
- rowObjs[i].cells[0].onmouseout=function (){
- this.style.background="#ff6666";
- }
- }
- //屏蔽菜單的菜單
- pop.document.oncontextmenu=function (){
- return false;
- }
- //選擇右鍵菜單的一項後,菜單隱藏
- pop.document.onclick=function (){
- pop.hide();
- }
- //顯示菜單
- pop.show(event.clientX-1,event.clientY,width, rowCount*50,document.body);
- return true;
- }
- </script>
- <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
- <script language="JavaScript" type="text/javascript">
- function $(obj){
- return document.getElementById(obj);
- }
- function pop(obj){
- var h = parseInt($("popDiv").currentStyle.height);
- $("popDiv").style.height = (h + obj) + "px";
- if(parseInt($("popDiv").style.height) < 2)
- {
- window.clearInterval(timer);
- $("popDiv").style.display = "none";
- }
- if(parseInt($("popDiv").style.height) >= 200){
- window.clearInterval(timer);
- }
- }
- var timer;
- function runtimer(obj){
- timer = window.setInterval(function(){pop(obj)},10);
- }
- window.onload = function(){
- runtimer(2);
- }
- //每隔10秒調用show方法,若是顯示則隱藏,若是隱藏則顯示
- setInterval( show ,10000 );
- function show(){
- if ( $("popDiv").style.display == "none" )
- {
- $("popDiv").style.display = "inline"
- runtimer(2);
- }
- else
- {
- runtimer(-2);
- }
- }
- </script>
- <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
- <script type="text/javascript">
- var speed=40;//數值越大,速度越慢
- var demo2=document.getElementById("demo2");
- var demo1=document.getElementById("demo1");
- var demo=document.getElementById("demo");
- demo2.innerHTML=demo1.innerHTML;
- demodemo.scrollTop=demo.scrollHeight;
- function MarqueeUp(){
- if(demo2.offsetTop-demo.scrollTop<=0)
- demo.scrollTop-=demo2.offsetHeight;
- else{
- demo.scrollTop++;
- }
- }
- var MyMar=setInterval(MarqueeUp,speed);
- demo.onmouseover=function() {clearInterval(MyMar);}
- demo.onmouseout=function() {MyMar=setInterval(MarqueeUp,speed);}
- </script>
<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>- <div id="demo2"></div></div>