常用JS編譯代碼

2013-09-09

JavaScript (Window控制) +筆記

Reverse li 選項

$(需要reverse的UL物件ID).append($(需要reverse的UL物件ID).children('li').get().reverse()); //將主選單項目到轉

windows mouse event

$("#obj").mouseout(function(){動作}) : #obj 物件觸發此離開動作時,此物件的內容物並不被包括在此物件當中
$("#obj").mouseleave(function(){動作}) : #obj 物件觸發此離開動作時,此物件的內容物視同為此物件的一部分

How to Control windows

window 如果指的是目前的window,請用self

self.screenX

目前視窗位置

//all browser
window.screenX
window.screenY

//IE
window.screenTop
window.screenLeft

視窗重新移位置

window.moveTo(left,top)

開啟新視窗 (resizable在IE才有用)

window.open(‘url’,’window titile’,’width=x’,’height=y’,’left=x’,
’top=y’,’toolbar=no’,’menubar=no’,’scrollbars=no’,
’resizable=false’,’location=no’,’status=no’);

視窗大小控制

window.resizeBy(x,y);相對位置
window.resizeTo(x,y);絕對位置

 

 

How to Get Screen W/H or Windows W/H

視窗大小

document.documentElement.clientWidth;//視窗寬度
document.documentElement.clientHeight;//視窗長度

螢幕大小

screen.width;//螢幕寬度
screen.height;//螢幕長度

 

偵測流覽器使否有flash

if (navigator.mimeTypes ["application/x-shockwave-flash"] == undefined){
download flash
}else{
   $("#someDiv").show ();
}

 

亂數產生方式

var num = Math.floor(Math.random() * 90000) + 10000;

90000 ---> 位數最大數字
10000 ---> 位數最小數字

var num = Math.floor(Math.random() * 90000+1);

90000+1 ---> 五位數+1,所以製作六位數字的亂數

 

MouseEvent 控制選項的重要差別


資料參考: http://api.jquery.com/mouseover/

mouseover 滑入時,動作不引用在子物件
mouseout 滑出時,動作不引用在子物件
mouseenter 滑入時,動作引用在子物件
mouseleave 滑出時,動作引用在子物件



 

Window重新導向

window.location="New Location";



AS3和JS的參數傳送方式

JS to AS

AS3: 

ExternalInterface.addCallback(”JS的function”,AS的function); 
function AS的function(變數:String):void { 
       取得JS變數值 

JS: 

function setBox(o) { 
     thisMovie(”swf的ID”).JS的function(變數);
 

AS to JS

AS3: 

ExternalInterface.call(JS的function(“‘+變數+’”)); 

JS: 

function JS的function(getChartData(變數) { 
     執行的動作, 取得變數值

 

以下為範例
as3
 
//按鈕
fnBtnEvent(按鈕一);
fnBtnEvent(按鈕二);
fnBtnEvent(按鈕三);

//定意按鈕
function fnBtnEvent(btnObj) {
    
btnObj.addEventListener(MouseEvent.CLICK, fnEventHandler);
     
btnObj.addEventListener(MouseEvent.ROLL_OVER, fnEventHandler);
     
btnObj.addEventListener(MouseEvent.ROLL_OUT, fnEventHandler);
     
btnObj.buttonMode = true;
     
btnObj.mouseChildren = false;
}

//按鈕事件
function fnEventHandler(evt:MouseEvent):void {
     
var evtType = evt.type;
     
var evtTarget = evt.target;
     
switch (evtType) {
          
case "rollOver":
                
evtTarget.gotoAndPlay("hover");
          
break;
          
case "rollOut":
                
evtTarget.gotoAndPlay("hout");
          
break;
          
case "click":
                
evtTarget.gotoAndPlay("active");
                
ExternalInterface.call("fnAScallJS(" + evtTarget.name + ")"); //將該按鈕的名稱當參數傳送給javascript function
          
break;
       
}
}
 
 
Javascript
 
//flash與JS的共用function function fnGetStart(target) {
//定義彈跳視窗的大小和置中顯示 var windowWidth = screen.width; var windowHeight = screen.height; var popWidth, popHeight, paddingTop, paddingLeft, toURL, winTitle;

//按鈕事件的動作 switch (target) { case "按鈕一":
//關閉視窗 window.close(); break; case "按鈕二":
//開啟一個800x600的置中視窗
toURL = "網址";
winTitle = "視窗名稱"; popWidth = 800; popHeight = 600; paddingTop = (windowHeight - popHeight) * 0.5; paddingLeft = (windowWidth - popWidth) * 0.5; window.open(toURL winTitle, "height=" + popHeight + ",width=" + popWidth + ",top=" + paddingTop + ",left=" + paddingLeft + ",toolbar=0,menubar=0,scrollbars=0,resizable=1,location=0,status=0");
break; case "按鈕三":
//直接連結到一個網址
toURL = "網址";
window.location.href = toURL; break; default: alert("您所選取的按鈕名稱是:" + target + ",目前並無任何動作!"); break; //若該按鈕並沒有在此function中找到定義,則秀出該按鈕的名稱 } }  
//jquery的swfObject var flashvars = {}; var params = { wmode: "transparent" }; var attributes = {};
var swfW = 800;
var swfH = 600; swfobject.embedSWF("swf檔案", "內崁入的容器ID", swfW ,

 

Cache控制選項

history.back(); //回上頁

 

Iframe控制選項

parent.fnName(); //呼叫主框架的js function

Contact

Github

Codepen

歡迎參觀我的賣場
© 2013 Copyright Digishot Web | Design Tools
Visitors【630388】
digishot webdesign studio