所以我在我的网站上有这个代码和锚点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 :(得分: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;
});
答案 1 :(得分:0)
删除return false;
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
//return false; This prevents the normal action of the anchor
});
也许添加target =&#34; _blank&#34;到您的链接,以便他们将在新标签页中打开
<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop" target="_blank">Domestic Electrical installation</a>