平滑滚动 JavaScript 影响模态功能
Smooth scrolling JavaScript affecting Modal functionality
我正在使用以下JavaScript为我的页面执行平滑滚动。
$(function(){
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^'//,'') == this.pathname.replace(/^'//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
这工作正常,但它对我的模态有不良影响,因为它会阻止模态打开。我的滚动版:
<a href="#location" class="btn btn-circle">
<i class="fa fa-5x fa-angle-double-down animated"></i>
</a>
对于我的模态:
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" class="collapsed" href="#1">
<span>Press for magic</span>
</a>
</h4>
</div>
<div class="collapse panel-collapse" id="1">
<div class="panel-body">
<p>Some magic here...</p>
</div>
</div>
</div>
</div>
有没有办法修改 JavaScript 以仅对滚动产生影响并保留模态?
只需将点击函数中的a[href*="#"]:not([href="#"])
替换为类名,然后将该类名放在<a>
标签中,如下所示:
$(function(){
$('.hashscroll').click(function() {
if (location.pathname.replace(/^'//,'') == this.pathname.replace(/^'//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
和
<a class="hashscroll" href="#location" class="btn btn-circle">
<i class="fa fa-5x fa-angle-double-down animated"></i>
</a>
不要对整个页面进行动画处理。只需为要移动的内容设置动画即可。
<body>
<div class="animateThis"></div>
<div class="modal"></div>
</body>
相关文章:
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 打开一个模态并将其链接到AngularJS中的指令
- SemanticUI模态not onDeny/onApprove事件未激发
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- 如何通过所选索引(AngularJS)在模态弹出窗口中显示数据
- 包含数据库中相关信息的开放模态
- bootstrap消除模态并显示另一个模态
- 模态提示-如何重写此代码
- 模态框无法正常工作
- 将数据传递给由服务创建的Ionic模态
- 模态无法访问其显示功能
- 如何制作“;模态构象”;此函数调用中的功能
- 如何通过jQuery在模态窗口中实现此功能
- 平滑滚动 JavaScript 影响模态功能
- 模态框功能齐全-les.links don'不起作用
- 如何在模态中为图像添加滑动功能
- 如何在具有设计功能的模态中显示忘记的错误消息
- 最干净的方式,使模态依赖于一个功能?AngularJS
- Knockout Js绑定到具有撤消功能的编辑模态
- 如何定义“物质化”?模态“before"(beforeload)功能