2013-05-27 103 views
1

我希望我的「新聞箱」div從頁面底部向上滑動到頁面上方的頁腳上方(稍微延遲一點),然後我想如果用戶點擊「newsClose」,DIV會下滑。嘗試過的東西,但沒有成功(在JS沒有知識) - 爲您的幫助向上滑動DIV,然後點擊

的jsfiddle感謝:http://jsfiddle.net/7whAs/

JS

$(document).ready(function() { 
    jQuery('#newsbox').delay(2000).slideDown(); 
    jQuery(function() { 
    jQuery('.newsClose').click(function (e) { 
     e.preventDefault(); 
     jQuery('#newsbox').slideUp(); 
    }); 
}); 

HTML

<div id="newsbox"> 
    <div class="news-text"> 
     <p>Blablablablabla blablabla blablabla <a href="index.html">Blabla blabla</a></p> 
     </div> 
    <div class="news-close"> 
     <a href="#" class="newsClose">Close X</a></div> 
    </div> 
</div> 

CSS

#newsbox { 
    background-color: #CCC; 
    display:none; 
    width: 750px; 
    z-index: 10000; 
    float: left; 
    position: fixed; 
    bottom: 45px; 
    padding-top: 10px; 
    padding-right: 20px; 
    padding-bottom: 10px; 
    padding-left: 20px; 
} 

.news-text { 
    float: left; 
    width: 600px; 

} 
.news-text p { 
    color: #666666; 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 11px; 
    line-height: 13px; 
} 
.news-continue { 
    float: left; 
    width: 70px; 
    text-align: center; 
    margin-top: 10px; 
    margin-left: 20px; 
} 
.news-close { 
    width: 60px; 
    margin-right: auto; 
    margin-left: auto; 
    text-align: center; 
} 
.news-close a, 
.news-text a { 
    color: #3E718E; 
} 
.news-continue a, 
.news-close a { 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 11px; 
    line-height: 11px; 
    font-weight: normal; 
    color: #FFF; 
    display: block; 
    padding-top: 5px; 
    padding-right: 0px; 
    padding-bottom: 5px; 
    padding-left: 0px; 
    background-color: #3E718E; 
} 

.news-close a:hover { 
    text-decoration: underline; 
} 
.news-continue a:hover, 
.news-close a:hover { 
    background-color: #333333; 
    color: #FFF; 
} 

.news-close { 
    float: right; 
    width: 60px; 
    font-size: 10px; 
    line-height: 11px; 
    text-align: right; 
} 

回答

5

你近了。你的小提琴先啓用jQuery的(它的左側),然後消除你的第二DOM準備功能:

演示http://jsfiddle.net/7whAs/1/

$(document).ready(function() { 
    jQuery('#newsbox').delay(2000).slideDown(); 
    jQuery('.newsClose').click(function (e) { 
     e.preventDefault(); 
     jQuery('#newsbox').slideUp(); 
    }); 
}); 
+0

此外,如果你決定使用jQuery的速記「$」的工作(這應該沒問題),你可以堅持在代碼的其餘部分(用$替換jQuery),但這只是美觀。 – Pevara