I just created a ribbon style menu the problem is in FireFox and Google Chrome browsers when you mouseenter and document click the first element in the list always blinks I dont have this problem in IE could someone check out my page and view the source and have a look at my jquery code and see if you can find whats causing this small glitch - the page is here
It must be todo with my mouseenter function I pass in this selected_slide(this)
mouseenter:
function select_slide(element) {
if($(element).hasClass('.nav_divider_before')) return
$('.nav_browse_ul li')..removeClass('active');
$(element).addClass('active');
if($(element).attr('data-id') != null) {
var current_content = $('#' + $(element).attr('data-id'));
selected_slide = current_content;
$('.ribbon_slides').show();
rotate_ribbon_slides(element);
if(isAnimating) return;
if(!isOpen) {
isAnimating = true;
$('.ribbon_slides').animate({'width': '+=' + (current_content.width() + 20).toString() })
$('.ribbon_panel').animate({'width': '+=' + (current_content.width() - 14).toString()}, function(){
isOpen = true;
isAnimating = false;
})
}
}
}
document click
$(document).click(function(e) {
/**/
if(!$(e.target).closest('.ribbonmenu').length) {
if($('.nav_browse_ul li').hasClass('active')) {
$('.nav_browse_ul li').removeClass('active');
}
$('.ribbon_slides').animate({'width': '-=' + ($(selected_slide).width() + 20).toString()});
$('.ribbon_panel').animate({'width': '-=' + $(selected_slide).width()}, function() {
$('.nav_browse_ul li.nav_divider_before').css('margin-right', '0px');
$('.ribbon_slides').hide();
});
isOpen = false;
}
})
Related
I have a button with an href attribute and when i click on it, it will scroll to the div with id="buttonhref_value" ...I need some extra space before the div so that people can view my fixed menu bar on top..so its top - 60...it works fine in chrome, and safari..in IE no matter how much extra space i give ,it always scroll to the top of the div..i mean the div is now below the menu bar..can anyone help ?
$.fn.smoothScrollOnClick = function () {
return this.each(function () {
$(this).on('click', function (event) {
if (this.hash !== '') {
var hash = this.hash;
if ($('' + hash + '').length > 0) {
var stop = ($('' + hash + '').offset().top - 60 );
$('html, body').animate({ scrollTop: stop
}, 200, function () {
window.location.hash = hash;
});
event.preventDefault();
}
}
});
});
};
how to prevent bubbling or "out of control" when user hover(mouseenter) multiple times . When user hover i'm using slideDown and slideUp for mouseleave and delay i set 250. I can only fix this if delay i set to 1 ms. Below is my script :
$("#nav li").mouseenter(function (e) {
e.stopPropagation();
if (!is_opened) {
var left = $(this).position().left;
$(this).children('div').css('left', '-' + left + 'px');
$(this).children('div').slideDown(delay, function () {
// Animation complete.
is_opened = true;
});
}
return false;
});
$("#nav li").mouseleave(function () {
if (is_opened) {
$(this).children('div').slideUp(delay, function () {
// Animation complete.
is_opened = false;
});
} else {
setTimeout(function () {
if (is_opened) {
$('#nav li:first-child').children('div').slideUp(delay, function () {
// Animation complete.
is_opened = false;
});
}
}, 1000);
}
return false;
});
You can check my JsFiddle here
Reproduce a Problem
Hover Catalogue multiple times and stop hover(but point your cursor at Catalogue), you will see the dropdown will hide but actually it should slide down.
I think your issue is caused by the is_opened flag and then the animation being run along side changing the left css property
If you change your mouse enter and leave js to the following
$("#nav li").each(function() {
//cache vars for better performance
var li = $(this);
var left = $(this).position().left;
var divs = li.children('div');
//change div left first so it only changes once
divs.css('left', '-' + left + 'px');
//do mouse enter and leave stuff
li.mouseenter(function (e) {
e.stopPropagation();
divs.stop(true, true).slideDown(delay);
});
li.mouseleave(function () {
divs.stop().slideUp(delay);
return false;
});
});
it should work: Example
What I'm trying to do is, whenever we leave the button and then move back to the grey content box, the slideUp will stop and the content will be slideDown again.
It works just fine using jQuery 1.x (edge), but when I use jQuery 1.10 the slideUp just stop, and not continue to slideDown again.
Do you guys have any idea which part should I change to make it work on jQuery 1.10?
$(function () {
var show_content = '';
$('.nav-content > div').hide();
$('.btn1,.btn2').mouseenter(function (e) {
var target = $(e.currentTarget).attr('class');
console.log('Mouse Enter : ' + target);
if (target == 'btn1') {
show_content = $('.con1');
} else if (target == 'btn2') {
show_content = $('.con2');
}
show_content.stop().slideDown(300);
});
$('.btn1,.btn2').mouseleave(function (e) {
var target = $(e.currentTarget).attr('class');
show_content.stop().slideUp(2000);
});
$('.nav-content').mouseenter(function (e) {
show_content.stop().slideDown(300);
});
$('.nav-content').mouseleave(function (e) {
show_content.stop().slideUp(2000, 'swing', function (e) {
console.log('Hide done');
});
});
});
Here's my Fiddle
http://jsfiddle.net/PmJt2/2/
I can't figure out why not continue to slideDown again, but slideToggle works.
Use .slideToggle() instead of slideDown and slideUp
I've been working on this jQuery effect heres the fiddle:
http://jsfiddle.net/abtPH/26/
Everything's pretty good so far, however when I click on the elements too fast it seems to get buggy and get weird behavior. If you take your time and click on the elements it works fine.
I've tried using :animate
stuff to make sure the animation ends before the user can click on the next one. I do not like this approach though because from a end user it seems like the effects are laggy. I want the user to be able to click on the elements fast and have the desired effect.
Here's my jQuery so far:
$('li').on('click', function (e) {
e.preventDefault();
var active = $(this).siblings('.active');
var posTop = ($(this).position()).top;
if (active.length > 0) {
var activeTop = (active.position()).top;
if (activeTop == posTop) {
$(this).find('.outer').fadeIn('medium', function () {
active.toggleClass('active', 400).find('.outer').fadeOut('medium');
});
} else {
$(this).siblings('.active').toggleClass('active', 400).find('.outer').slideToggle();
$(this).find('.outer').slideToggle();
}
} else {
$(this).find('.outer').slideToggle();
}
$(this).toggleClass('active', 400);
});
$('.outer').on('click', function (e) {
return false;
});
Use .finish() complete all the queued animation before beginning a new one
$('li').on('click', function(e){
e.preventDefault();
var active = $(this).siblings('.active');
var posTop = ($(this).position()).top;
if (active.length > 0) {
var activeTop = (active.position()).top;
if (activeTop == posTop) {
$(this).find('.outer').finish().fadeIn('medium', function(){
active.finish().toggleClass('active', 400).find('.outer').finish().fadeOut('medium');
});
} else {
$(this).siblings('.active').finish().toggleClass('active', 400).find('.outer').finish().slideToggle();
$(this).find('.outer').finish().slideToggle();
}
} else {
$(this).find('.outer').finish().slideToggle();
}
$(this).finish().toggleClass('active', 400);
});
$('.outer').on('click', function(e){
return false;
});
Demo: Fiddle
I have a textbox. its name is PhoneNumber. I want to do a popup if len(input value)=0.
When I do a tag it doesn't work. (I looked in debug mode)
When I do it in an another Jq script which is already works. it works but popup window stay screen only a few mil seconds so I can not do anything.
I am new in programming and I am still learning. İf you help me I will be happy. Thanks.
<script type="text/javascript">
$('#PhoneNumber').bind('keypress', function (e) {
if (e.keyCode == 13) {
var test = $('#PhoneNumber').val().length;
if (test == 0) {
alert('At Least');
/* $('a.login-window').one(function () {
var loginBox = $(this).attr('href');
//Fade in the Popup and add close button
$(loginBox2).fadeIn(300);
//Set the center alignment padding + border
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;
$(loginBox).css({
'margin-top': -popMargTop,
'margin-left': -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
return false;
});
// When clicking on the button close or the mask layer the popup closed
$('a.close, #mask').live('click', function () {
$('#mask , .login-popup').fadeOut(300, function () {
$('#mask').remove();
});
return false;
});*/
}
else
{
alert('At Least');
$("#PhoneNumber").val("");
$('#PhoneNumber').focus();
}
}
});
</script>
Always put your jquery code into:
$(document).ready(function() {
//Your code
});
This makes sure that the DOM is loaded when you attach event handlers to elements.
And for me it looks like the return false of your one callback function is killing the fadeIn before it's finished.
You could add the event object e as a parameter of the function and then use e.stopPropagation() and e.preventDefault() instead of return false; like that:
$('a.login-window').one(function (e) {
e.stopPropagation();
e.preventDefault();
//Your code
});