所以我的网站上有这个带有锚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>
感谢您的帮助
要在新窗口中打开链接,必须将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;
});
删除返回false;
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
//return false; This prevents the normal action of the anchor
});
也许可以将target="_blank"添加到您的链接中,这样它们就会在新的选项卡中打开
<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop" target="_blank">Domestic Electrical installation</a>