gpt4 book ai didi

javascript - 单击导航栏上的任何内容都会打开弹出窗口

转载 作者:行者123 更新时间:2023-12-03 05:23:42 26 4
gpt4 key购买 nike

我面临的问题是,每当我想单击导航栏中的任何项目时,都会打开弹出窗口。如果该项目有链接“#”。我想要的是弹出窗口应该仅在单击“登录/注册”项时打开。这是实际 codepen 版本的链接,您可以在这里查看:click here or go to https://codepen.io/codyhouse/pen/pIrbg

jQuery(document).ready(function($) {
var $form_modal = $('.cd-user-modal'),
$form_login = $form_modal.find('#cd-login'),
$form_signup = $form_modal.find('#cd-signup'),
$form_forgot_password = $form_modal.find('#cd-reset-password'),
$form_modal_tab = $('.cd-switcher'),
$tab_login = $form_modal_tab.children('li').eq(0).children('a'),
$tab_signup = $form_modal_tab.children('li').eq(1).children('a'),
$forgot_password_link = $form_login.find('.cd-form-bottom-message a'),
$back_to_login_link = $form_forgot_password.find('.cd-form-bottom-message a'),
$main_nav = $('.hmodal');

//open modal
$main_nav.on('click', function(event) {

if ($(event.target).is($main_nav)) {
// on mobile open the submenu
$(this).children('ul').toggleClass('is-visible');
} else {
// on mobile close submenu
$main_nav.children('ul').removeClass('is-visible');
//show modal layer
$form_modal.addClass('is-visible');
//show the selected form
($(event.target).is('.cd-signup')) ? signup_selected(): login_selected();
}

});

//close modal
$('.cd-user-modal').on('click', function(event) {
if ($(event.target).is($form_modal) || $(event.target).is('.cd-close-form')) {
$form_modal.removeClass('is-visible');
}
});
//close modal when clicking the esc keyboard button
$(document).keyup(function(event) {
if (event.which == '27') {
$form_modal.removeClass('is-visible');
}
});

//switch from a tab to another
$form_modal_tab.on('click', function(event) {
event.preventDefault();
($(event.target).is($tab_login)) ? login_selected(): signup_selected();
});

//hide or show password
$('.hide-password').on('click', function() {
var $this = $(this),
$password_field = $this.prev('input');

('password' == $password_field.attr('type')) ? $password_field.attr('type', 'text'): $password_field.attr('type', 'password');
('Hide' == $this.text()) ? $this.text('Show'): $this.text('Hide');
//focus and move cursor to the end of input field
$password_field.putCursorAtEnd();
});

//show forgot-password form
$forgot_password_link.on('click', function(event) {
event.preventDefault();
forgot_password_selected();
});

//back to login from the forgot-password form
$back_to_login_link.on('click', function(event) {
event.preventDefault();
login_selected();
});

function login_selected() {
$form_login.addClass('is-selected');
$form_signup.removeClass('is-selected');
$form_forgot_password.removeClass('is-selected');
$tab_login.addClass('selected');
$tab_signup.removeClass('selected');
}

function signup_selected() {
$form_login.removeClass('is-selected');
$form_signup.addClass('is-selected');
$form_forgot_password.removeClass('is-selected');
$tab_login.removeClass('selected');
$tab_signup.addClass('selected');
}

function forgot_password_selected() {
$form_login.removeClass('is-selected');
$form_signup.removeClass('is-selected');
$form_forgot_password.addClass('is-selected');
}

//REMOVE THIS - it's just to show error messages
$form_login.find('input[type="submit"]').on('click', function(event) {
event.preventDefault();
$form_login.find('input[type="email"]').toggleClass('has-error').next('span').toggleClass('is-visible');
});
$form_signup.find('input[type="submit"]').on('click', function(event) {
event.preventDefault();
$form_signup.find('input[type="email"]').toggleClass('has-error').next('span').toggleClass('is-visible');
});


//IE9 placeholder fallback
if (!Modernizr.input.placeholder) {
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.val(input.attr('placeholder'));
}
}).blur();
$('[placeholder]').parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
}

});


jQuery.fn.putCursorAtEnd = function() {
return this.each(function() {
// If this function exists...
if (this.setSelectionRange) {
// ... then use it (Doesn't work in IE)
// Double the length because Opera is inconsistent about whether a carriage return is one character or two. Sigh.
var len = $(this).val().length * 2;
this.setSelectionRange(len, len);
} else {
// ... otherwise replace the contents with itself
// (Doesn't work in Google Chrome)
$(this).val($(this).val());
}
});
};
<!-- Fixed navbar -->
<nav id="home" class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div>
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="index.html">
<img class="img-responsive" alt="logo" src="img/logo.png">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-right navbar-main-collapse hmodal">
<ul class="nav navbar-nav" style="padding-right:15px;">
<li><button class="ui inverted compact small yellow button" style="margin-top:8px; ">Become a Partner</button></li>
<li class="active"><a href="#">Track</a></li>
<li><a href="tel:+917878000666" rel="nofollow"><i class="fa fa-phone"></i>Call +91 7878 000 666</a></li>
<li><a href="#notification"><i class="fa fa-bell" aria-hidden="true"></i></a></li>
<li><a class="cd-signin" href="#Login">Login/Signup</a></li>
<li><a href="#"><i class="fa fa-map-marker" aria-hidden="true"></i> Location</a>
<div class="dialog" style="display:none">
<div class="title">Add Event</div>
<form action="#" method="post">

<input type="submit" value="Ok"/>
</form></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->

</nav>

提前谢谢,我被困在这里两天了。帮帮我。

最佳答案

打开模态的原始脚本是通过nav-menu打开的。您需要将单击事件指向这两个按钮。请尝试:

//open modal
$(".cd-signin, .cd-signup").on('click', function(event){
$main_nav.children('ul').removeClass('is-visible');
$(this).children('ul').toggleClass('is-visible');
$form_modal.addClass('is-visible');
if($(this).hasClass("cd-signin"))
{
login_selected();
}
else
{
signup_selected();
}

});

关于javascript - 单击导航栏上的任何内容都会打开弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41254187/

26 4 0