I'v placed a jquery slider in a Bootstrap tab but the tab does not function unless the window is resized. I'm guessing this is because it's being created in an empty container instead of being fired once the container exists.
I've tried triggering a window resize event upon clicking the tab:
$('#myTab a[href="#slider"]').click(function (e) {
e.preventDefault()
$(this).tab('show');
jQuery(window).trigger('resize');
$('.swiper-container').css('height','100%').css('width','100%');
})
But it didn't work.
JS Fiddle LINK
Call Swiper function once slider tab is displayed..
var isSliderActive = false;
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
if($(this).attr('href') == "#slider"){
if(isSliderActive === false){ //If slider is not active
var mySwiper = new Swiper('.swiper-container',{
pagination: '.pagination',
paginationClickable: true
});
}
isSliderActive = true;
}
});
Updated jsFiddle
Expand and collscape div:
var open = false;
$('#SlideButton').click(function () {
if (open === false) {
$('#SlideContent').animate({ height: '650px' }, 600);
$('#SlideContent').css('display', 'block');
$(this).css('background-position', 'bottom left');
open = true;
}
else {
$('#SlideContent').animate({ height: '0' }, 600, function () {
$('#SlideContent').css('display', 'none');
});
$(this).css('background-position', 'top left');
open = false;
}
});
Related
$(document).click(function (event) {
if ($("#sidenav").width() != 0) {
$("#sidenav").css({ 'width': '0' });
}
});
$("#sidenav").click(function (e) {
e.stopPropagation();
return false;
});
$("#navHome").click(function () {
$("#navHome").attr("href", "/public/templates/default/index.html");
$("#sidenav").css({ 'width': '0' });
});
1) The $(document).click(function (event) function closes the nav bar if user click anywhere outside the navbar
2) The $("#sidenav").click(function (e) function prevents nav bar from closing if user click anywhere inside the navbar
3) Now because of the e.stopPropagation(); in the second function, when I click on the navHome it did close the navBar but didn't take me to the index page. In other words, $("#navHome").attr("href","/public/templates/default/index.html"); doesn't work.
Is there a work around for this? Thanks!
Do not cancel the click if the target is a link
$("#sidenav").click(function (e) {
if(!$(e.target).closest("a").length) {
e.stopPropagation();
return false;
}
});
Have this code and tried to hide my side navbar when clicked outside the #nav, got this error.
Cannot read property 'addEventListener' of null
$( document ).ready( function() {
setTimeout(function(){
$('.menu-opener').click(function(){
$('#nav').toggleClass('active');
});
let slide = document.querySelector('#nav .active');
slide.addEventListener('click', function(e) {
if (e.target !== slide) return;
$('#nav').removeClass('active');
});
}, 1000);
});
answer is that you need to detect click outside of div you are trying to hide:
$(window).click(function() {
//Hide the menus if visible
});
//stopping above function from running when clicking on #nav itself
$('#nav').click(function(event){
event.stopPropagation();
});
Try this inside setTimeout
$('body').on('click','#nav .active', function(e){
// your logic
})
OR
$( "'#nav .active'" ).bind( "click", function(e) {
// your logic
});
instead of
let slide = document.querySelector('#nav .active');
slide.addEventListener('click', function(e) {
if (e.target !== slide) return;
$('#nav').removeClass('active');
});
Got this working with
$(document).click(function(event) {
if(!$(event.target).closest('#nav').length && !$(event.target).closest(".menu-opener").length)
{
$('#nav').removeClass('active');
}
});
I am working on jQuery UI dialog, JS Fiddle for reference. If you observe on click of close window(dialog), the links are not getting enabled, however the links should be enabled based on relative window close. How can I relate the closing dialog window with the respective link and enable it again?
$(function() {
function opener(params){
var _params = params;
for (var obj in _params){
dialogOpener(_params[obj]);
}
function dialogOpener(selector){
$('#'+selector.linkSelector).on('click', function(ev){
ev.preventDefault();
ev.stopPropagation();
var url = $(this).attr('href');
if ($(ev.target).hasClass('disabled')) {
return false;
} else{
$('#'+selector.moduleSelector).dialog({width: 800, position: 'top'}).load( url);
$(this).addClass('disabled');
}
});
}
}
opener([
{ linkSelector: 'google', moduleSelector: 'googleModule'},
{ linkSelector: 'facebook', moduleSelector: 'facebookModule'},
{ linkSelector: 'yahoo', moduleSelector: 'yahooModule'},
{ linkSelector: 'gmail', moduleSelector: 'gmailModule'}
]);
});
Try adding an event that is fired on close of the dialog when you initialize your dialog box that re-enables the link. For instance your dialogOpener function could look something like this:
function dialogOpener(selector){
$('#'+selector.linkSelector).on('click', function(ev){
ev.preventDefault();
ev.stopPropagation();
var url = $(this).attr('href');
var selected = $(this);
if ($(ev.target).hasClass('disabled')) {
return false;
} else{
$('#'+selector.moduleSelector).dialog({
width: 800,
position: 'top',
close: function(event,ui) {
selected.removeClass('disabled');
}
}).load( url);
selected.addClass('disabled');
}
});
}
JSFiddle: http://jsfiddle.net/mobj45kt/2/
jQuery Dialog API for the close event: http://api.jqueryui.com/dialog/#event-close
I am having an issue with my slideToggle function. Once pressed it opens up the way I need it to. But when I scale the browser to test the responsive flow to the site the slideToggle still stays active instead of sliding down. I tried a few functions but nothing seems to work. Below is the scrip I am using without the code to slide down when it hits a specific screen resoultion. How would I go about fixing this issue?
$('#more').click(function () {
var open = $('header').is('.open');
$('#footerPanel')['slide' + (open ? 'Up' : 'Down')](400);
$('header').animate({
bottom: (open ? '-' : '+') + '=120' }, 400, function () {
$('header').toggleClass('open');
});
});
$('#menu').click(function () {
if ($('header').is('.open')) {
$('header')
.removeClass('open')
.animate({
'bottom': "-=120"
}, function () {
var $footer = $('.activetoggle');
if ($footer.length)
$footer
.toggleClass('activetoggle footerButton')
.text('Footer');
});
$('#footerPanel').slideUp(400);
}
});
$('.footerButton').click(function () {
var $this = $(this);
$this.toggleClass('footerButton');
if ($this.hasClass('footerButton')) {
$this.text('Footer');
} else {
$this.text('Close');
}
$(this).toggleClass('activetoggle');
});
My Code
http://jsfiddle.net/wyze/XqUp4/4/
Try if this works for you. I have added to check whether the width is 780(you can change it), when the panel to slide down. Try adding this in you fiddle and check if this works
$(window).resize(function(){ //check when window resize
if($(window).width() < 780){ // check when the window width is less than 780
if ($('header').is('.open')) {
$('header')
.removeClass('open')
.animate({
'bottom': "-=120"
});
$footer = $('.activetoggle');
if ($footer.length) {
$footer.toggleClass('activetoggle footerButton').text('Footer');
}
$('#footerPanel').slideToggle(400);
}
}
});
My document click function isn't hiding my menu when I click the document outside of my menu. When I click the img it shows the menu and when I click the img again it hides it but when I document click I want it to hide the menu does any one know what I'm doing wrong and how to make it work.
var visible = false;
var id = $(this).attr('id');
$(document).not('#' + id + ' div:eq(1)').click(function () {
if (visible) {
$('.dropdownlist .menu').hide();
visible = false;
}
});
$(this).find('div:eq(1)').click(function (e) {
var menu = $(this).parent().find('.menu');
if (!visible) {
menu.show();
visible = true;
} else if (visible) {
menu.hide();
visible = false;
}
menu.css({ 'left': $(this).position().left + $(this).width() - menu.find('ul').width(),
'top': $(this).position().top + $(this).height() });
})
I had a similar problem and solved it with the following code:
$("body").mouseup(function(){
if (visible) {
$('.dropdownlist .menu').hide();
visible = false;
}
});
instead of your $(document).not(.. code.
//add event.stopPropagation() when the user clicks on a .menu element
$('.menu').on('click', function (event) {
//.stopPropagation() will stop the event from bubbling up to the document
event.stopPropagation();
});
//add the click event handler to the image that will open/close .menu elements
$('img').on('click', function (event) {
//we call .stopPropagation() again here so the document won't receive this event
event.stopPropagation();
//cache .menu element
var $div = $('.menu');
//this if statement determines if the .menu should be shown or hidden, in my example I'm animating its top property
if ($div.css('top') == '-50px') {
$div.stop().animate({top : 0}, 250);
} else {
$div.stop().animate({top : '-50px'}, 150);
}
});
//add click event handler to the document to close the .menu
$(document).on('click', function () {
$('div').stop().animate({top : '-50px'}, 150);
});
jsfiddle: http://jsfiddle.net/jasper/n5C9w/1/