gpt4 book ai didi

javascript - 单击并向下滚动页面上的滑入式号召性用语 div buggy

转载 作者:行者123 更新时间:2023-11-28 05:48:29 26 4
gpt4 key购买 nike

我有一个 div,单击它会在右侧滑入,但如果它尚未打开或打开,我也试图让它在滚动时滑入。因此,您可以单击按钮使其滑入,或者如果在您向下滚动页面时将其关闭,它会打开,然后在几秒钟后消失,或者如果单击按钮。

我有点让它工作,但有很多错误。任何帮助将不胜感激!

http://jsfiddle.net/abennington/50tab7vh/2/

HTML:

<div class="floating-form" id="contact_form">
<div class="contact-opener">CTA Box Toggle</div>
<div class="contact_body">

<h3>This is a CTA Box</h3>
<p>On click it will slide out and on scroll it will scroll out as you get down the page and then go away.</p>

<a href="#" class="btn btn-primary btn-block"><i class="fa fa-calendar-o"></i> CTA Button</a>


</div>
</div>

jQuery:

$(document).ready(function(){ 
var buttonhieght = $('.contact-opener').width()-52;
var popdiv = $('#contact_form').width();
var _scroll = true, _timer = false, _floatbox = $("#contact_form"), _floatbox_opener = $(".contact-opener") ;
_floatbox.css("right", "-"+ popdiv+"px"); //initial contact form position
_floatbox_opener.css("left", "-"+ buttonhieght+"px"); //initial contact form position

//Contact form Opener button
_floatbox_opener.click(function(){
if (_floatbox.hasClass('visiable')){
_floatbox.animate({'right': '-'+ popdiv+'px'}, {duration: 300}).removeClass('visiable');
}else{
_floatbox.animate({"right":"0px"}, {duration: 300}).addClass('visiable');
}
});
});
$(document).on('scroll', function() {
var popdiv = $('#contact_form').width();
var _floatbox = $("#contact_form");
var scrollTop = $(window).scrollTop();
if (scrollTop > 700) {
if (_floatbox.hasClass('visiable')){
_floatbox.animate({'right': '-'+ popdiv+'px'}, {duration: 300}).removeClass('visiable');
}else{
_floatbox.animate({"right":"0px"}, {duration: 300}).addClass('visiable');
}
}
})

CSS:

/* floating box style */
.floating-form * { color: #fff; }
.floating-form {
width:300px;
max-width: 300px;
top: 100px;
font: 13px Arial, Helvetica, sans-serif;
background: #F9F9F9;
background: #754c24;
color: #fff;
right: 10px;
position: fixed;
z-index: 1000;
box-shadow: -2px -0px 8px rgba(43, 33, 33, 0.06);
-moz-box-shadow: -2px -0px 8px rgba(43, 33, 33, 0.06);
-webkit-box-shadow: -2px -0px 8px rgba(43, 33, 33, 0.06);
}
.contact-opener {
position: absolute;
text-transform:uppercase;
left: -100px;
transform: rotate(-90deg);
top: 150px;
background-color: #754c24;
padding: 10px 15px;
color: #fff;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.43);
cursor: pointer;
border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
box-shadow: -2px -0px 8px rgba(43, 33, 33, 0.06);
-moz-box-shadow: -2px -0px 8px rgba(43, 33, 33, 0.06);
-webkit-box-shadow: -2px -0px 8px rgba(43, 33, 33, 0.06);

}
#contact_form .contact_body { padding: 30px 30px 10px 30px; }
#contact_form .contact_body h3 { margin: 0rem 0 1.0rem; }
#contact_form .contact_body ol { padding: 5px 0px 10px 20px; }
#contact_form .contact_body li { padding: 8px 0px; font-weight: 700; }
#contact_form .contact_body .btn-primary { background: rgba(35,26,19,0.9); margin-bottom: 20px; }

最佳答案

问题是滚动处理程序永远不会分离,因此 #contact_form 一直显示/隐藏,直到所有滚动事件都被“清除”。我已经更新了您的 fiddle ,使其仅在页面滚动到某个点后才尝试显示一次 #contact_form,然后删除滚动处理程序。

我认为这就是您想要的:http://jsfiddle.net/50tab7vh/3/

关于javascript - 单击并向下滚动页面上的滑入式号召性用语 div buggy ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37472381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com