2016-05-29 71 views
0

我在我的腳本中使用show函數。我也在該函數中傳遞參數,但它顯示錯誤。即時通訊使用下面的代碼,而點擊一個按鈕,我稱之爲next()函數。隱藏功能參數不工作在jquery

function next() { 
    $('#img1').hide('slide', { direction: 'left' }, 1400); 
} 

這不適用於我。顯示此錯誤Uncaught TypeError: n.easing[this.easing] is not a function。而沒有參數傳遞,它工作正常。

+0

你想用動畫? – Mohammad

+0

我需要隱藏並顯示img,然後點擊next和prev按鈕,所以我會繼續。 – Raja

+0

@Raja用戶loccai(缺乏評論代表atm。)想知道你是否能夠擺脫這一點。您的代碼片段按預期工作...: -/ – ZF007

回答

1

使用此代碼

$("button").click(function(){ 
 
    $("div").animate({width:'toggle'}, 350); 
 
});
div { 
 
    width: 100px; 
 
    height: 100px; 
 
    background: green; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button>Show/hide</button> 
 
<br/><br/> 
 
<div></div>

+0

感謝您的答案,但我想隱藏左側。像一張幻燈片。 http://jsfiddle.net/xu3ck/16/這裏工作,但在我的代碼不工作。 – Raja

2

怎麼樣定製動畫如下:

HTML

<div class='div1' id="div1"></div> 
<button id="showhide"></button> 

CSS

.div1{ 
    height:100px; 
    width:100px; 
    position:absolute; 
    left:0; 
    top:100px; 
    background-color:red; 
    transition:all 0.5s; 
} 
.hide{ 
    width:0; 
} 

JS

document.getElementById("showhide").addEventListener("click",function(){ 
    if(document.getElementById("div1").classList.contains("hide")){ 
     document.getElementById("div1").classList.remove("hide"); 
    } 
    else{ 
     document.getElementById("div1").classList.add("hide"); 
    } 
})