[英]Scroll in the top and open a new page with anchor
So I have this code in my site with anchor jquery pages, this code scroll in the top but dont open a new page when i click the text button 因此,我在带有锚定jquery页面的站点中拥有此代码,此代码在顶部滚动,但是当我单击文本按钮时不打开新页面
code js: 代码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;
});
code html, text button: 代码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>
thank you for your help 谢谢您的帮助
To get the link to open in a new window you will have to set the target
attribute to _blank
要在新窗口中打开链接,您必须将
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>
and in your click listener you will want to return true
so it does not prevent the default behavior 并且在您的点击侦听器中,您将希望返回
true
因此它不会阻止默认行为
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return true;
});
Remove the return false; 删除return false;
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
//return false; This prevents the normal action of the anchor
});
Maybe add target="_blank" to your links so they will open in a new tab 也许将target =“ _ blank”添加到您的链接中,以便它们在新标签页中打开
<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop" target="_blank">Domestic Electrical installation</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.