2015-09-02 64 views
0

我想使用jQuery做一個滑動輪播,這裏是代碼,我不知道這個函數究竟做了什麼?這個函數在javascript中做了什麼?

$w.bind('resize.example', function() { 
    var nw = $w.width(); 
    if (nw < 900) { 
     nw = 900; 
    } 

    $c.width(nw * 3); 
    $c.parent().width(nw); 

}).trigger('resize.example'); 

回答

0

我相信你正在使用的版本低於jQuery的V1.7,因爲你正在使用bind()這是1.7後棄用的版本。

$w.bind('resize.example', function() {

這條線結合$w元件上的事件resize.exampleresize.example是自定義事件,我相信$wwindow包裝在jQuery中的對象。

}).trigger('resize.example');

此觸發事件resize.example,這是很常見的。這用於在頁面加載時運行事件處理程序。

var nw = $w.width(); 
if (nw < 900) { 
    nw = 900; 
} 

這個代碼設置的nw可變900如果width$w小於900值。

$c.width(nw * 3); 
$c.parent().width(nw); 

的碼本部分設置的nw$c至3倍的寬度。 和$c的父元素的寬度設置爲nw的值。

0
//Bind a custom event named 'resize.example' to the $w element 
$w.bind('resize.example', function() { 

    //Store the $w width in a variable named 'nw' 
    var nw = $w.width(); 

    if (nw < 900) { 
     //If nw < 900 --> set the 'nw' var equal to 900 
     nw = 900; 
    } 

    //Set the $c element width equal to 900*3=2700px 
    //*** $c is not defined here.. 
    $c.width(nw * 3); 

    //Set the parent of $c equal to 900px 
    $c.parent().width(nw); 

}).trigger('resize.example'); //Trigger the custom event to execute the function