2014-10-29 41 views
0

所以我有這樣的代碼在我的網站的錨jQuery的網頁,在上面這段代碼滾動,但不要打開一個新頁面,當我點擊文本按鈕滾動頂部和錨翻開新的一頁

代碼JS:

$(document).ready(function(){ 

    //Check to see if the window is top if not then display button 
    $(window).scroll(function(){ 
     if ($(this).scrollTop() > 100) { 
      $('.scrollToTop').fadeIn(); 
     } else { 
      $('.scrollToTop').fadeOut(); 
     } 
    }); 

    //Click event to scroll to top 
    $('.scrollToTop').click(function(){ 
     $('html, body').animate({scrollTop : 0},800); 
     return false; 
    }); 

代碼HTML,文本按鈕:

<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop">Domestic Electrical installation</a> 
<a href="<?php $url->_getURL2('openpage'); ?>" class="scrollToTop">Comercial Electrical installation</a> 

感謝你的幫助

+0

究竟什麼是你的問題打開? – ray9209 2014-10-29 19:51:54

+0

和你的問題是? – bipen 2014-10-29 19:52:57

+0

@ ray9209和bipen,我編輯的問題。 tnx – user3480332 2014-10-29 19:55:46

回答

0

ŧ Ø獲得一個新窗口中打開,你將不得不在target屬性設置爲_blank

<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop" target="_blank">Domestic Electrical installation</a> 
<a href="<?php $url->_getURL2('openpage'); ?>" class="scrollToTop" target="_blank">Comercial Electrical installation</a> 

,並在點擊監聽器,你將要返回true所以它不會阻止默認行爲

$('.scrollToTop').click(function(){ 
    $('html, body').animate({scrollTop : 0},800); 
    return true; 
}); 
鏈接
+0

正在工作..謝謝!!! – user3480332 2014-10-29 20:09:04

0

刪除返回false;

$('.scrollToTop').click(function(){ 
    $('html, body').animate({scrollTop : 0},800); 
    //return false; This prevents the normal action of the anchor 
}); 

也許添加目標=「_空白」到你的鏈接,這樣,他們將在一個新的標籤

<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop" target="_blank">Domestic Electrical installation</a>