jQuery isotope inside tab/accorion - tabs

I am trying to run a 4 column masonry isotope item inside a tab/accordion. I found that I will need to use the layout, to make the isotope work, when tab element is visible.
So I tried this;
jQuery(function ($) {
$('.tab_title').click(function(){
$('.iso-container').isotope({
itemSelector : '.iso-item',
layoutMode:'masonry',
masonry:{
columnWidth: 300
}
});
});
});
When I click the tab (.tab_title), isotope appears, but in one column, taking entire container width. How can I solve this?
To mention, I have tried $('.iso-container').isotope('layout') as well. This also shows one item taking entire width of the container.

I was able to solve it using:
$('.iso-container').isotope( 'reloadItems' ).isotope( { sortBy: 'original-order' } );
If in case, images are overlapping on each other, use imagesLoaded.
var $grid = $('.iso-container').imagesLoaded( function() {
$grid.isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' });
});

Related

Sliding drop-down is not working perfectly

I am trying to add animation to my dropdown-menu ... It is working perfectly on large screens but on small phones and tablets (when toggle navigation appears) there is a problem: when it should slide up the drop-down list disappears without sliding up properly as you can see in my
DEMO . Please try to open in it in small browser size and click on "services" to slide down and up .
I have tried another solution using jquery:
$(function () {
$('.dropdown').on('show.bs.dropdown', function (e) {
$(this).find('.dropdown-menu').first().stop(true, true).slideDown();
});
// ADD SLIDEUP ANIMATION TO DROPDOWN //
$('.dropdown').on('hide.bs.dropdown', function (e) {
e.preventDefault();
$(this).find('.dropdown-menu').first().stop(true, true).slideUp(400, function () {
$('.dropdown').removeClass('open');
$('.dropdown').find('.dropdown-toggle').attr('aria-expanded', 'false');
});
});
});
But as you can see in this Bootply DEMO (resize your browser to a phone screen size), when sliding down, at the end there is a gray space that appears then disappears directly.
What I really need is a normal working slide animation down and up. Any suggestions of how can I adjust at least one of both methods?
I find the solution , you should remove the scrollbar from the navbar.
so add this simple code to your css file :
.navbar-collapse {
overflow: hidden;
}
you can take a look at the Demo here : https://jsfiddle.net/u9pvtLpw/2/

Bootstrap 4 collapsible on hover with multiple items

I have found a few ways to to expose the collapsible accordion function in bootstrap, however I am unable to customise it in a way that only one panel-collapse is triggered when hovering the div.panel-heading > a element.
I am doing the following:
$('div.panel-heading a').hover(function () {
$('.panel-collapse').collapse('show');
}, function() {
$('.panel-collapse').collapse('hide');
});
}
But whenever I hover over the a element all panel-collapse elements open and close. How can I isolate each if they are not children of panel-heading?
Fiddle here: http://jsfiddle.net/Tupira/084z33g5/1/
Try this code:
$('div.panel-heading a').hover(function () {
$('.panel-collapse', $(this).closest('.panel')).collapse('show');
}, function() {
$('.panel-collapse', $(this).closest('.panel')).collapse('hide');
});

Disabling Page Scroll when Cursor is Over Div (Chatango)

I'm adding a Chatango HTML5 chat box to my website, but when users scroll up or down in the chat box, it also scrolls up or down the rest of the page. I've been experimenting with different codes I've found on this site, but so far nothing has worked.
I thought I found a solution here: How to disable scrolling in outer elements? and applied it to my chatroom. It works exactly how I want it to on this codepen editor: http://codepen.io/EagleJow/pen/QbOBJV
But using the same code in JSFiddle: https://jsfiddle.net/4bm6ou90/1/ (or on my actual website) does not prevent the rest of the page from scrolling. I've tested it in both Firefox and Chrome with the same results.
Here's the javascript:
var panel = $(".panel");
var doc = $(document);
var currentScroll;
function resetScroll(){
doc.scrollTop(currentScroll);
}
function stopDocScroll(){
currentScroll = doc.scrollTop();
doc.on('scroll', resetScroll);
}
function releaseDocScroll(){
doc.off('scroll', resetScroll);
}
panel.on('mouseenter', function(){
stopDocScroll();
})
panel.on('mouseleave', function(){
releaseDocScroll();
})
Any ideas?
It didn't work on JSFiddle because I didn't have jQuery set on the side menu and it didn't work on my website because the '$' symbol in the javascript conflicted with that same symbol in the jQuery (or something like that).
Here's the JSFiddle with better code and set to load jQuery: https://jsfiddle.net/4bm6ou90/7/
The Javascript:
$.noConflict();
jQuery( document ).ready(function( $ ) {
$(".panel").on("mouseenter", function(){
$(document).on("scroll", function(){
$(this).scrollTop(0);
});
});
$(".panel").on("mouseleave", function(){
$(document).off("scroll");
});
});
Also gotta have that jQuery CDN in the html head section.

Prevent screen from moving when clicking on <a href=></a>

I'm using <a href> element along with :target css selector to show a <div> which by default is set to display:none. Problem is, that when I click on the link to show that <div>, it is automatically scrolling down my site towards that <div>.
Is there a way to stop the screen movement?
Unfortunately I am not yet proficient in anything besides CSS and HTML.
You can use event.preventDefault() to avoid this. Something like this:
$('a.yourclass').click(function(e)
{
//your code
e.preventDefault();
});
OR:
link
in the link enter:
Link here
You'll need JS anyway:
// (in jQuery)
$el.on('click', function(e) {
// find current scroll position
var pos = document.body.scrollTop || document.documentElement.scrollTop;
// let normal action propagate etc
// in the next available frame (async, hence setTimeout), reset scroll posiion
setTimeout(function() {
window.scrollTo(0, pos);
}, 1);
})
I don't know if this will flicker the screen. It might. It's a horrible hack either way.
In my Chrome, there's no flicker: http://jsfiddle.net/rudiedirkx/LEwNd/1/show/
There are two ways to tell the browser we don't want it to act:
The main way is to use the event object. There's a method
event.preventDefault().
If the handler is assigned using on (not by
addEventListener), then we can just return false from it.
Example:
Click here
or
here
This is a bit of a hack but you could use a basic css work around:
CSS only Example
#div1 {
height: 0;
overflow:hidden;
}
#div1:target {
height: auto;
margin-top: -110px;
padding-top: 110px;
}
#div2 {
background:red;
}
Click to show
<div id="div1">
<div id="div2">Content</div>
</div>
If you need it to be a little more flexible you can add some js...
More Flexible Example with JS
$('a').click(function () {
$('#div1').css({
'margin-top': 0 - $('#div1').position().top + $(window).scrollTop(),
'padding-top': $('#div1').position().top - $(window).scrollTop()
});
});
Basically you're pulling the top of div1 up with the negative margin and then pushing div2 back down with the padding, so that the top of div1 rests at the top of the window... Like I said its a hack but it does the trick.
Those links are anchor-links and by default made for those jumps :) You could use JS to prevent the default behaviour in some way. For example using jQuery:
$('a').click(function(e){e.preventDefault();});
or by default add return false; to the links
Avoid using :target all together and just use onclick event.
function myFunction()
{
document.getElementById('hiddenDiv').style.display = 'block';
return false;
}

Html <ul> TranslateX

i have a ul-Element with 30 li-Elements, but only 20 Elements are shown, the overflow is hidden. Now i want to show the last 20 Elements. Is there a translateY(X)-Method for the ul-Element or something else?
Fesp
This solution is shooting into that big vague question. Hopefully it hits!
<ul id="ul_id" style="height:200px;overflow:hidden;">
<li></li>
...
</ul>
<script type="text/javascript">
document.getElementById('ul_id').scrollTop=150;
</script>
You can scroll a div with "scrollTop" in javascript. Just set the desired offset in pixels.
You'll need to scroll the element to reveal children that are "below the fold". Depending on if they're stacked on top of each other or in a row you'll need to use ul.scrollTop or ul.scrollLeft (from JavaScript).
Not a CSS HTML method I know. But the only way I can think to do what you ask (if I'm guessing correctly) is via jQuery, so.....
This will dynamically add an additional li with "See More..." when clicked, it will show more items on the list.
$(function() {
var hiddenStuff = $('.list li:gt(5)').hide();
if (hiddenStuff.size() > 0) {
var theCaption = '... See More';
$('.list').append(
$('<li class="more" id="toggler">' + theCaption + '</li>')
.toggle( function() {
hiddenStuff.slideDown(1000);
$(this).text('...See Less');
},
function() {
hiddenStuff.slideUp(1000);
$(this).text(theCaption);
})
);
}
});
jsFiddle Demo HERE
A CSS-only solution, which may work for you here: CSS-ONLY DEMO