我有一个网页,我想通过单击一个按钮(div 和按钮都有固定位置)来制作一个出现在屏幕右侧的 div 我通过使用 jQuery 淡入/淡出使它出现
它工作正常,但是当我单击按钮时,页面会自动滑动到顶部
代码:
<div class="fixedDiv">
<div class="fixedDiv liveSupportFrame" style="background: #f8aa00;display: none" id="lsf">
<div class="container" style="background-color:#d8d6d6;">
............
</div>
</div>
<a class="btn btn-warning sideBtn" onclick="showOrHideLiveSupport();" role="button" href="#">FAQ</a>
CSS代码:
.fixedDiv{
position: fixed;
bottom: 25%;
right: 0em;
}
.fixedDiv .liveSupportFrame{
margin-right: 2em;
margin-bottom: 1em;
font-size:1.6vw;
bottom: 30%;
}
JS代码:
var isLsfOpen = 0;
function showOrHideLiveSupport() {
if(!isLsfOpen){
showLiveSupport()
}
else{
hideLiveSupport()
}
}
function showLiveSupport() {
$('#lsf').fadeIn();
isLsfOpen=true;
}
function hideLiveSupport() {
$('#lsf').fadeOut();
isLsfOpen=false;
}
那是因为href="#"
. event.preventDefault();
在您的处理程序中使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句