滚动到顶部,打开一个带有锚点的新页面
Scroll in the top and open a new page with anchor
所以我的网站上有这个带有锚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>
相关文章:
- 使用 JQuery 打开一个新的 php 页面
- 在IE11中,点击next或back按钮,使用intro.js打开一个新页面
- 与node.js的get/post混淆,并试图创建一个新页面
- window.打开一个新页面,然后单击新页面中的链接 - JavaScript
- 加载另一个相同页面时,使用新数据激活第一个网页
- 在当前页面中加载一个新的谷歌地图,加载AJAX
- 打开一个新页面作为模式窗口
- 在javascript中使用dblclick事件打开一个新页面
- 在Rails中更改选择值时加载一个新页面
- 在JavaFX webview中加载一个新页面
- 在php中按下一个按钮打开一个新页面
- 如何在浏览器中从iframe中加载一个新页面?
- 自动加载一个新页面,只访问正文中的一个元素
- 在新窗口中打开一个新页面,打印并关闭它
- 在网站退出时打开一个新页面
- 如何从javascript函数在jQuery Mobile中打开一个新页面
- 为什么不开窗户?位置加载一个新页面
- 如何在jsp页面上每隔10秒包含一个新页面
- 为什么javascript: on webview会跳转到一个新页面?
- 我试图在表单提交到一个新页面后,根据用户选择的多个选项(Javascript.html)重定向表单