SmoothDivScroll jQuery Plugin not working if JS files are loaded asynchronously - javascript

I'm using SmoothDivScroll and it was working great until I tried to load all the JS files asynchronously. I use my own async loading pattern using Ryan Grove's Lazyload.js but to be sure, I also tested with Modernizr's load/complete pattern and got the same result. I tested with a copy of the quick demo part from SmoothDivScroll's homepage and just added Modernizr. Without Modernizr, it was fine, but when I added Modernizr and its load/complete pattern to the head, and commented out all the JS before the end body tag, it wasn't working anymore. When you hover over the right arrow nothing happens, while hovering over the left causes the images to flicker. It should work the same either way. The Moderizr block should be equivalent to all the ones below it:
<script type="text/javascript">
Modernizr.load([ {
load: [
'//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js',
'/js/jquery-ui-1.8.23.custom.min.js',
'/js/jquery.mousewheel.min.js',
'/js/jquery.kinetic.js',
'/js/jquery.smoothdivscroll-1.3-min.js'
],
complete:
function () {
$(document).ready(function () {
$("#makeMeScrollable").smoothDivScroll({
mousewheelScrolling: "allDirections",
manualContinuousScrolling: true,
autoScrollingMode: "onStart"
});
});
}
}
]);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script src="/js/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
<script src="/js/jquery.mousewheel.min.js" type="text/javascript"></script>
<script src="/js/jquery.kinetic.js" type="text/javascript"></script>
<script src="/js/jquery.smoothdivscroll-1.3-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#makeMeScrollable").smoothDivScroll({
mousewheelScrolling: "allDirections",
manualContinuousScrolling: true,
autoScrollingMode: "onStart"
});
});
</script>

I have modified a code segment as below
complete:
function () {
$("#makeMeScrollable").smoothDivScroll({
mousewheelScrolling: "allDirections",
manualContinuousScrolling: true,
autoScrollingMode: "onStart"
});
}
}
Attaching ready event handler to the document on complete of Modernizr won't work as the document is already loaded and parsed by the browser.

Related

jQuery .tap event not working

I can't figure out why the jQuery tap event isn't even getting a respond when I test it. I put in an alert and I haven't gotten it to pop up at all. My code looks like this:
var calendarOpen = false;
$('.calendar').on("tap", function () {
alert('1');
if (calendarOpen == false) {
$('.login-body').animate({left: '90%'}, 300);
$('.calendar-body').animate({right: '10%'}, 300);
calendarOpen = true;
} else {
$('.login-body').animate({left: '0px'}, 300);
$('.calendar-body').animate({right: '50%'}, 300);
calendarOpen = false;
}
});
I have the script and css pages attached and I've checked for any typos. I copied the jQuery documentation and I'm still having problems. Thanks for the help.
These are my included scripts and the code provided above is under main.js.
<script src=http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js></script>
<script src=http://code.jquery.com/ui/1.10.3/jquery-ui.js></script>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="scripts/main.js"></script>
You need to load your JS files in this order:
<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>
reference: http://jquerymobile.com/demos/1.0/docs/api/globalconfig.html

Jquery .click not firing

Trying to learn JQuery here, im starting off really simple.
When I click the button, the page reloads and nothing happens.
Heres my JS:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$("#submitShout").click(function() {
alert('hi');
});
</script>
Here's my html:
<div class="panel right">
<form name="shout" >
<textarea name="text" id="text" class="ribbitText"></textarea>
<input type="submit" id="submitShout" value="Ribbit!">
</form>
</div>
i think you forgot document.ready..
$(function () { //<--- here..the codes below is called whn document is ready
$("#submitShout").click(function () {
alert('hi');
});
});
Make sure you include jQuery reference and you code surrounded with
$(function(){
});
as
$(function () {
$("#submitShout").click(function () {
alert('hi');
});
});
or click binded at the end of the document
Just try this,
$("#submitShout").on("click", function() {
alert('hi');
});
If it is lower version Jquery, try this.
$("#submitShout").live("click", function() {
alert('hi');
});
jQuery 1.9 version
$(function(){
$("#submitShout").on('click',function(){
//your code
});
});
jQuery version lower than 1.9
$(function(){
$("#submitShout").live('click',function(){
//your code
});
});
that's a really old jquery version, upgrade it to something newer:
https://developers.google.com/speed/libraries/devguide#jquery
I guess Either you are missing the doc ready handler or the jQuery lib:
first try with this:
$(function(){
$("#submitShout").click(function() {
alert('hi');
});
});
then this one:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
$("#submitShout").click(function() {
alert('hi');
});
});
</script>
make sure jQuery is loaded
use the latest jQuery library
check the error console (using chrome developer tools or firebug for firefox
try changing your jQuery to
code:
$(function(){
$("#submitShout").click(function(e) {
e.preventDefault();
alert('hi');
return false;
});
});
Try this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#submitShout").click(function(event) {
alert('hi');
event.preventDefault();
});
});
</script>

using yep/nope with document.ready

I am using yepnope.js but having a slight issue with on load loading a function
in the head i include yep nope and make a call to the relevant js file
<script type="text/javascript" src="/code/trunk/javascript/external/modernizr/modernizr-development.js"></script>
<script type="text/javascript" src="/code/trunk/javascript/external/yepnope.1.5.3-min.js"></script>
<script type="text/javascript">
yepnope({
test: Modernizr.mq('only all and (max-width: 700px)'),
yep: ['/templates/client/jquery/qff/plugin.mobile.js'],
nope:['/templates/client/jquery/qff/plugin.website.js']
});
</script>
and then at the bottom of the page
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("#mainContent").setupQantas({
startSlide: 1,
googleAnalytics:1,
googleCode:""
});
});
</script>
so i am looking at this on a main screen. so it's suppoed to call in plugin.mobile.js
in the plugin.mobile.js file
(function( $ ){
$.fn.setupQantas = function( options ) {
// Create some defaults, extending them with any options that were provided
var settings = $.extend( {
startSlide: 1,
googleAnalytics:0, // 1 sends to google
googleCode: ""
}, options);
var methods = {};
return this.each(function() {
if (settings.startSlide === 1) {
alert("slide = 1");
} else {
alert("slide > 1");
}
});
};
})( jQuery );// JavaScript Document
instead of giving the alert slide 1 it has the error
jQuery("#mainContent").setupQantas is not a function
if i dont use yepnope and just have it in a script tag it works. There seems to be a delay on when the yepnope loads in the js file and doesnt seem to do before doc.ready
is there a way around this?
thanks
Yes there is a delay. That's all the point behind an asynchronous script loader.
You should use a callback after the script is loaded by yepnope. Check the complete and callback options.
here is the code
<script type="text/javascript">
yepnope({
test: Modernizr.mq('only all and (max-width: 700px)'),
yep: ['/templates/client/jquery/qff/mobile.js'],
nope:['/templates/client/jquery/qff/website.js'],
complete: function () {
jQuery("#mainContent").setupQantas({
startSlide: 1,
googleAnalytics:1,
googleCode:""
});
}
});
</script>

simple JQuery example is causing me troubles for unknown reason

I'm relatively new to JQuery and would like to try something. I just followed a simple tutorial to start up with on http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
So I specified my script in the :
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
alert("Hello world!");
});
});
</script>
and included a test link in the :
Link
however, when I refresh thet document my browser keeps saying
TypeError: Property '$' of object [object Window] is not a function
which I can understand for "normal" JavaScript but I believe this kind of function is new in JQuery. Can someone assist mer here, please?
links:http://wittmerperformance.com/site/
Did you embed the jquery library?
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
Further more I think that currently "on" is state-of-the-art as in:
$(document).ready(function() {
$("a").on('click', function() {
alert("Hello world!");
});
});
try this:
jQuery(document).ready(function($) {
$("a").click(function() {
alert("Hello world!");
});
});
The reason for the issue that you are facing could be that you haven't included JQuery library or it may be due to conflict, give it a try using
jQuery(document).ready(function ($) {
$("a").on('click', function() {
alert("Hello world!");
});
});
<script type="text/javascript">
$(document).ready(
function() {
$("a").click(
function(){
alert("Hello world!");
});
});
</script>
this is a working example.simpler. in your example you fotgot to close a function you started. count ( { } ) ; you are missing }) at the end. it shold work fine yours too.
full working example below:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$("a").click(
function(abc){
alert("Hello world!");
abc.preventDefault();
return false;
});
});
</script>
</head>
<body>
<a>some link</a>
</body>
</html>

Any specific order for Java script and jquery

I am using one java script and one jquery in my html file in head tag,
but my problem both the scripts are not working, i have used one slide show script and one nav menu script, in this both only one is working , is there any specific order to write these scripts ,
please find the below script order i have used , i am getting only slideshow. please help me out .
<script type="text/javascript"> google.load("mootools", "1.2.1");</script>
<script type="text/javascript" src="Js/MenuMatic_0.68.3.js" type="text/javascript"
charset="utf-8"> </script>
<script type="text/javascript">
window.addEvent('domready', function () {
var myMenu = new MenuMatic();
});</script>
<script type="text/javascript" src="Js/jquery.min.js"></script>
<script type="text/javascript" src="Js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="Js/slides.min.jquery.js"></script>
<script type="text/javascript">
$(function () {
$('#slides').slides({
preload: true,
preloadImage: 'img/loading.gif',
play: 5000,
pause: 2500,
hoverPause: true
});
});
</script>
It looks like you have MooTools and jQuery loading on the same page which will work but you will have to replace the short hand jQuery function. jQuery uses $(function) shorthand for jQuery(function) and that shorthand notation could cause problems.
You will need to use the jQuery.noConflict() function anywhere jquery and it's plugins were using the $.
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(function () {
$j('#slides').slides({
preload: true,
preloadImage: 'img/loading.gif',
play: 5000,
pause: 2500,
hoverPause: true
});
});
</script>

Categories