iScroll 4 fixed menu, unable to scroll rest of page - iscroll

I'm using iScroll for a horizontal, fixed position menu. It works great, however I'm unable to vertically scroll the rest of the page in a mobile browser. It works fine in a pc/mac resized browser window, just not on mobile. I've tried Safari on iPhone and Chrome and Dolphin on Android.
Any ideas how I can get the page to scroll too?
I've played with the vScroll, hScroll, etc options but haven't been able to solve the issue:
<nav id="mainNav">
<ul class="pagesIcons bottom">
<li style="background-color:#000000" class="active selected current youarehere">
<a href="#" class="inner">
<div class="buttonIcon">
<img src="/content/icons/002.png">
</div>
<div class="buttonText">
Homepage
</div>
</a>
</li>
<li style="background-color:#383838" class="">
<a href="#" class="inner">
<div class="buttonIcon">
<img src="/content/icons/002.png">
</div>
<div class="buttonText">
Gallery
</div>
</a>
</li>
<li style="background-color:#5c5c5c" class="">
<a href="#" class="inner">
<div class="buttonIcon">
<img src="/content/icons/004.png">
</div>
<div class="buttonText">
Events
</div>
</a>
</li>
........
</ul>
</nav>
I'm initialising it with:
var myScroll;
function loaded() {
myScroll = new iScroll('mainNav', {
bounce: false
});
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);

Solved. I just had to remove:
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
Pretty obvious. This was preventing the default event on 'touchmove'. Durrrrrrr

You can fix this issue by applying this jquery, In place of ClassName you have to add the name of wrapper class in which you want scrolling, If you still face problem let me know I will try to help more.
$('.ClassName').bind('touchmove', function(e){
e.stopPropagation();
});

Related

How to stop the scrolling effect with jQuery slideToggle()

I'm new to jQuery and I have some issues to stop the scrolling effect. For context, I use this code for hide and show some section on button click.
This is my code:
jQuery(function($) {
$('.rv_button1').click(function(e) {
e.preventDefault();
$("#reveal1").slideToggle();
$('.rv_button1').toggleClass('opened closed');
});
});
I use wordpress with divi theme, the html is not really clear but this part is where my jQuery function is made for (sorry for my English though)
<div class="et_pb_button_module_wrapper et_pb_button_0_wrapper et_pb_button_alignment_center et_pb_module ">
<a class="et_pb_button et_pb_button_0 rv_button et_pb_bg_layout_light opened" href="http://valerieb30.sg-host.com/notre-equipe/#reveal">Québec</a>
</div>
<div id="reveal" class="et_pb_row et_pb_row_1 et_pb_equal_columns et_pb_gutters2" style="display: block;">
<div class="et_pb_column et_pb_column_4_4 et_pb_column_1 et_pb_css_mix_blend_mode_passthrough et-last-child">
<div class="et_pb_module et_pb_text et_pb_text_0 et_pb_text_align_left et_pb_bg_layout_light">
<div class="et_pb_text_inner"><h2>Cuisinistes</h2></div>
</div>
<div class="et_pb_module et_pb_de_mach_archive_loop et_pb_de_mach_archive_loop_0 main-loop loadmore-align- grid-layout-grid main-archive-loop

How to add a hover event handler in JQuery, that will just target sibling elements with the same parent element?

how to make hover over one div to trigger changes in another div, but not to affect to another div with Jquery. Here is example
I know for this option but It's not working for me
$(function() {
$(".single-holder-image").hover(function() {
$(".read-more-a-black", this).css('color', '#a2d0ba');
}, function() {
// on mouseout, reset the background colour
$(".read-more-a-black", this).css('color', '');
});
});
maybe I need to change html structure
<div class="big-holder">
<div class="single-post-holder">
<a class="" href="#">
<div class="single-holder-image">
<img src="https://i.picsum.photos/id/717/200/300.jpg?hmac=OJYQhMLNcYlN5qz8IR345SJ7t6A0vyHzT_RdMxO4dSc" alt="">
</div>
</a>
<div class="description-holder">
<p class="category name "></p>
<a class="read-more-a-black" href="#"><h5>Title 2</h5></a>
<a class="read-more-a-black-p" href="#">lorem test test test test</a>
<div class="pdf-holder">
<p>Tools:</p>
</div>
</div>
</div>
<div class="single-post-holder">
<a class="" href="#">
<div class="single-holder-image">
<img src="https://i.picsum.photos/id/717/200/300.jpg?hmac=OJYQhMLNcYlN5qz8IR345SJ7t6A0vyHzT_RdMxO4dSc" alt="">
</div>
</a>
<div class="description-holder">
<p class="category name "></p>
<a class="read-more-a-black" href="#"><h5>Title 2</h5></a>
<a class="read-more-a-black-p" href="#">lorem test test test test</a>
<div class="pdf-holder">
<p>Tools:</p>
</div>
</div>
</div>
</div>
Also, will I be able to do the same when the mouse is hover over the title to trigger image and gets a transform: scale?
Use $(this) in the .hover() event handler callback.
This way just the very element where the event occured will be selected.
After that some JQuery DOM traversing with .parents() and .find() and problem solved:
$(document).ready(function() {
$(".single-holder-image").hover(function() {
$(this).parents(".single-post-holder").find(".read-more-a-black").css('color', '#a2d0ba');
}, function() {
// on mouseout, reset the background colour
$(this).parents(".single-post-holder").find(".read-more-a-black").css('color', '');
});
});

Close Hamburger Menu after click event problem Jquery

I made a hamburger menu, and when I click on the links it closes it. Also has a logo which disappears when I click on the hamburger button.
The webpage has a mobile and a desktop computer version that doesn't have a hamburger menu.
But I have a problem. On the Desktop version, if I click on the links the Logo disappears as well.
I know that it does it because the hamburger-close-after-click event triggers it.
But I don't know how I could change it to make it work well.
jQuery Code
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const links = document.querySelectorAll('.nav-links li');
var mylogo = document.getElementById("myLogo");
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('open');
links.forEach(link =>{
link.classList.toggle("fade");
});
});
//logo-toggle
$(document).ready(function(){
$('.hamburger').click(function() {
$('.logo-container').toggle().delay( 800 );
});
});
// hamburger-close-after-click event
$( '.nav-links li a' ).on("click", function(){
$('#hamburgerID').click();
});
HTML Code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<nav>
<div class="hamburger" id="hamburgerID">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
</nav>
<header class="header" id="myHeader">
<div class="logo-container" id="myLogo">
<img src="./img/logo.png" alt="logo"/>
</div>
<nav>
<ul class="nav-links">
<li><a class="nav-link" href="#details">DETAILS</a></li>
<li><a class="nav-link" href="#description">DESCRIPTION</a></li>
<li><a class="nav-link" href="#aboutus">ABOUT US</a></li>
</ul>
</nav>
The problem with pictures
[
You can use JQuery.toggleClass() to add and remove CSS classes, instead of using JQuery.toggle(), e.g.:
$('.hamburger').click(function() {
$('.logo-container').toggleClass('open');
})
And then, in the CSS file, define the visibility depending on the screen size, e.g.:
.logo-container { display: 'none' }
.logo-container.open { display: 'block' }
#media (min-width: 1025px) {
.logo-container { display: 'block' }
}
(Note: You will want to decide yourself how to identify the appropriate size to hide and show the elements. See also e.g.: how-to-target-desktop-tablet-and-mobile)

Fullpage js slide effect?

I'm trying to use Fullpage.js. Here is my script:
<div id="fullpage" style="margin-top: 55px">
<div class="section" id="first" style="background-color: red">Some section - Home</div>
<div class="section" id="services" style="background-color: blue">Some section - Services</div>
<div class="section" id="why" style="background-color: green">Some section - Why</div>
<div class="section" id="portofolio" style="background-color: red">Some section - Portofolio</div>
<div class="section" id="price" style="background-color: blue">Some section - Price</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#fullpage').fullpage({
menu: '#navbarNav',
css3: true,
scrollingSpeed: 1000
});
});
</script>
The problem is, there is no slide effect in my HTML page. Any solutions? I don't see any errors in my browser console.
UPDATE
There is a second problem, When I scroll to random section then I click the menu, the anchor is not working, I mean it keeps at the section which I scroll.
You need to define your anchors in your script, like this:
$(document).ready(function() {
$('#fullpage').fullpage({
menu: '#navbarNav',
css3: true,
scrollingSpeed: 1000,
anchors:['first, 'secondPage', 'why', 'portofolio', 'price']
});
};
Source: https://github.com/alvarotrigo/fullPage.js#fullpagejs
please, could you insert your javascript code inside the $(document).ready() to be sure that it is ready to execute. In your case, it should be something like:
<script type="text/javascript">
$(document).ready(function() {
$('#fullpage').fullpage({
menu: '#navbarNav',
css3: true,
scrollingSpeed: 1000
});
};
</script>
Hope this can resolve your problem.
Thank you
You need to write the ID on href anchor attribute like this
<ul id=#menu>
<li data-menuanchor="first" class="active">
First
</li>
<li data-menuanchor="services" class="active">
Services
</li>
</ul>

Hidden elements are not loaded properly after being displayed

I have a tabbed toggle statistic page, which has 10 separate tabs that include charts. By clicking each tab, preloaded corresponding chart is being showed up. However, it does not scale into its container. More weird thing is, when I resize the window, visible chart is shown properly (I suppose it does some recalculation thingy). How should I modify my code so that it does that recalculation thingy after a click, or any suggestions on the problem?
Here is my jsfiddle:
http://jsfiddle.net/g66ut7c6/
<!--BEGIN TABS-->
<div class="tabbable tabbable-custom">
<ul class="nav nav-tabs">
<li>
<a href="#tab_1_1" data-toggle="tab">
1
</a>
</li>
<li>
<a href="#tab_1_2" data-toggle="tab">
2
</a>
</li>
<li>
<a href="#tab_1_3" data-toggle="tab">
3
</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="tab_1_1">
<div class="scroller">
<div class="col-md-6 col-md-offset-3">
<div class="portlet light">
<p> Piechart by ülkeler </p>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="tab_1_2">
<div class="scroller">
<div class="col-md-6 col-md-offset-3">
<div class="portlet light">
<p> Piechart by step dağılımı </p>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="tab_1_3">
<div class="scroller">
<div class="col-md-6 col-md-offset-3">
<div class="portlet light">
<p> Piechart by hasta sayısı ay </p>
</div>
</div>
</div>
</div>
</div>
</div>
<!--END TABS-->
Before resize
After a resize, the size is okay
I could not include charts in my jsfiddle because they contain some ruby code.
PS: Using Chartkick and Google Charts to draw charts, and MetronicJS for tabs.
Edit: The first chart that is visible by default is being display properly initially, however others are not. After a resize of a window when another chart is visible, the previous one gets broken again.
You can programmatically fire the 'resize' event:
window.dispatchEvent(new Event('resize'));
Just attach it to the 'click' event that shows the tab.
In your case:
$('div.tabbable > ul > li > a').click( function() {
window.dispatchEvent(new Event('resize'));
});
If your component doesn't resize as respond to the event, you could actually resize the window with:
window.resizeTo(width, height);
UPDATE:
If it is not posible to resize the window (see comments) you could try to redraw the chart when the tab becomes visible. Maybe in that way the chart is able to calculate properly the dimensions it needs to fit in. Something like:
$( 'div.tabbable > ul > li > a' ).click( function() {
myChart.draw( myData );
});
Hope it helps!