JQuery :: Next Step Executed Before Image Attributes Available
Dec 28, 2010
In the following code - Sometimes I get the correct image width and sometimes I get an image width that is ZERO. How do I make sure the loaded image attributes are there before I access them. Odd thing is if I click the same thumbnail twice I always get the width. If I click a thumbnail once I may get the width this time BUT when I refresh I may get a ZERO width.
Here is the code...
$(document).ready(function() {
$('#gallery a').click(function(evt) {
evt.preventDefault();
var oldImage = $('#photoBox img'); // Selects the current image
var newImage = new Image(); // Create a new image
var imagePath = $(this).attr('href'); // get the path to the image file to load that was clicked - via its href attr name
newImage.src = imagePath;// Set the newIamge.src to file name or Path
if (newImage.width < 600) // If the width is less than 600 calculate a new margin to center the new image {
var newMargin = (620 - newImage.width) / 2;
var newHtml = $('<img src="' + imagePath + '">');
$('#photoBox').css('margin-left',newMargin);
$('#photoBox').css('width',newImage.width);
} else
// assume width is 600 {
var newHtml = $('<img src="' + imagePath + '">');
$('#photoBox').css('width',newImage.width);
$('#photoBox').css('margin',5);
} newHtml.hide(); // hide the newHtml before prepending will fade it in
oldImage.hide(); // hide the old image
$('#photoBox').prepend(newHtml); // prepend the newHtml
newHtml.fadeIn(1000,function() { }); // now fade it in
});});
View 2 Replies
ADVERTISEMENT
Sep 28, 2009
I'm creating a step by step form using jquery ui tabs andvalidation plugin, the problem is that I've got just one form ( and Ihave to ) so on first step the form is validated but all errors anothers steps are displayed.I'm using an approach ofbut I've got specific messages and validations.Something like
var v=$("#saverForm").validate(
{
debug: true,
[code]....
View 1 Replies
View Related
Sep 10, 2009
In pseudo code, here's what I'm trying to do with some text:
shrinkText.changeText.EnlargeText.
The jQuery I'm using for this:
$('span#calendarNumber').animate({
color: '#999',
fontSize: '12px'
}, 500 ).html($('#calculatorSampleInPopup1').val()).animate({
color: '#900',
fontSize: '40px'
}, 2500, 'easeOutElastic' );
What happens visually upon triggering this is this:
- HTML content changes
- text shrinks
- text enlarges
I think what is happening is that the first animation is suppose to span 500 (miliseconds?) but jQuery doesn't pause for that, it just starts the animating and goes immediate to the second event which is to change the text. In otherwords, I think it's triggering correctly, it's just not producing the visual effect I want. Is the solution to put a pause of some sort between the first two events? If so, what's the proper method?
View 3 Replies
View Related
Jul 19, 2011
Im using the jquery form wizard [URL] to create a form wizard. In one of the steps i need to populate some inputs based on the value of another input from a previous step.How can i do this? For ex: On step 1 i have two inputs. In one of them i need a time interval in days. On step 2 i have a datepicker witch should have the value of the current time + the number of days from the input in step 1.
View 1 Replies
View Related
Jul 23, 2005
I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this? Code:
View 6 Replies
View Related
Dec 12, 2011
I have a application that uses jquery-1.6.4.jsandjquery-ui-1.8.14.custom.min.js. A call is made by a js file that works if I break on the call and single step using firebug but when run w/o the single step the call to the php in the server never seems to occure. IE doesn't seem to have this problem
View 4 Replies
View Related
Aug 10, 2011
i'm New to JQuery and I recently had a problem with encorporating a transition at the beginning and end of my carousel. I found that by default it would Fast Forward/Fast Rewind through all the images at the ends, rather than just jump to the slide and wrap.
I've managed to solve the issue (bar a transition effect from the last slide back to the first) it now jumps to slide one, rather than rewinding through all the images. However (and i know this sounds silly) but i'm having trouble doing the reverse. I'll add both the zip file to show a working model if interested and also post the 2 relevant functions :)
[Code]...
View 12 Replies
View Related
Jun 20, 2006
I need a dropdown menu that go directrly to the link on select.
I don't want a 2 steps dropdown (select + submit)
I rather want a submit on select.
Like the Apple Store Locator on apple.com.
This dropdown is connected to a MySQL DB with PHP.
View 2 Replies
View Related
Nov 29, 2011
i need to wrap the following code with (function($){ ... })(jQuery);But when i do so than the callbackfunction jsonpCallback will not be executed anymore.I hope someone can explain that to me...
// ( function($)
{$(document).ready(function() {
var error_container = $('#ul_demo_error')
[code]....
View 2 Replies
View Related
Apr 29, 2010
I have a div with a click event that fires a show('slow')... however if the user clicks on the div multple times the animation plays that many times... is there a way to make it so that the click event is only executable once the animation is complete?.
View 2 Replies
View Related
Jul 10, 2009
I am experiencing some crazy stuff, at least crazy to me Both the 'if' and 'else' blocks (according to firebug) are being executed in the following anonymous function:
[Code]...
View 10 Replies
View Related
Oct 13, 2010
I have some half-working script I'm playing with that I half-understand (this is the real problem) which I'm having troube debugging because it always does work when I refresh.So whenever I step through my functions with Firebug everything does what I expect it to do: but if then I re-invoke my onchange event, not every step is taken and it's hard to see why because I can't "see" what it's doing after the page has loaded and the script run at least once.This is for hide-and-show in a form and all the other versions I see online are even less understandable than what I've got so far. So I figure I'd better debug the one I have.Anyone know how to re-watch a script onevent?
View 4 Replies
View Related
May 10, 2010
I am trying to execute slightly more than "Hello, world" using .ajax() specifically and with both a success and error callback. I have:
[Code]...
View 1 Replies
View Related
Apr 23, 2009
Using ajax and jquery I'm calling a function on the server code that returns a javascript script that I need to assign to a div and get executed automatically when assigned.So far I couldn't do that, seems that the assigned script to the innerHTML of the div can'r be executed dynamically.Basically I'd like something like assign an alert('hello world') to the innerHTML and automatically see the pop up with the message.
View 12 Replies
View Related
Mar 22, 2010
I am new to all this but making good progress and having fun in the process. I have written quite a bit over recent weeks (including a few $.post / $.ajax calls) for various sites/applications but this one is really puzzling me. Here is a snippet of code that is causing me problems.
[Code]....
The problem is that execution jumps from line 2 to line 6 ... ignoring the function(data) and I am not sure why. I get the correct value of "team" arriving at the perl script .... and the perl writes the correct json back. I just can't think where else I need to look to debug this - as I said, I have done something similar 5-6 times over the last few weeks - all without a problem. So I am sure I am doing something stupid here.
View 3 Replies
View Related
Apr 29, 2011
Im having some troubles with some functions i launch in $(document).ready() to initialize the page. Then if i click on browser refresh everything goes fine... even more strange when i place alerts between then calls to these functions everything goes fine too... but the first time the page is loaded it seems that the functions are not executed at all.
View 3 Replies
View Related
Feb 18, 2011
I am a self thought web developer and am constantly having problems making sure that certain commands are finished executing before others are started. My most recent problem is trying to append a large amount of data, to a div, then sliding it down slowly. Since that data takes a while to append, the system is doing both at the same time, therefore not giving me the slide down effect. Here is the code:
$('#SomeDiv').append(data);
$('#image1').animate({"left": "+=300px","top": "-=200px"}, "slow");
$('#image2').animate({"left": "+=120px"}, "slow");
$('#Image3').animate({"top": "+=250px","left": "+=300px"}, "slow");
[Code].....
Where "SomeDiv" is part of "cpage" and "data" is a large amount of images. I would like to execute line 1 and then all the other lines simultaneously. It is currently executing all of the simultaneously.
View 6 Replies
View Related
Apr 27, 2010
I am building a navigation which animates width on mouseover and revert it on mouseleave. That navigation also supports keypress/keydown actions, so it behaves like you hover with the mouse and additionally opens the submenu too. My problem is, when using the keydown (C) function, the menu opens up perfectly but when I mouseover then, it fires the 1. function and behaves like it should, it closes. I tried to stop that when just using keydown, but somehow I am stuck with it. Here comes the code:
$
(
function
()
[Code]....
View 4 Replies
View Related
Dec 6, 2009
I'm using jQuery and i have an animation effect which is executed via two methods:-
method 1: clicking on a nav link.
method 2: manually scrolling past a specified point.
Now, since method 1 will make the page scroll to the relevant anchor, by it's nature, it will trigger method 2.
What i need is a way to prevent method 2 from executing if method 1 is in operation.
View 5 Replies
View Related
Mar 26, 2010
I have an unordered list with each LI having an onclick event of "changeTabContent". When the page loads, I trigger the active LI's click. On a click, first thing I do is remove the previous results, which are a UL living under the "li.active" element. Next, I move the "active" class to the LI that was pushed and off the old one. Next, I add a loading animation to the screen. Next I append a new UL to the new "li.active" and use the load() method to insert a bunch of LI's from a different page. onSuccess, I remove the loading animation. [note 1] Next, you'll see a hack I added, more on that in a minute... Last two steps are to add a "more" link to the bottom of the returned li's, if a link was passed into the function, and finally I remove a handful of LI's (excluding more link) so there are only "x" on the screen.
My #1 problem is that the more link is not showing up at times, and the cleanList function is not removing LI's. I believe the problem is that with the load being async, sometimes those last two steps are being hit, but there is no LI's in the DOM yet. You can see I tried to run a hack so the while loop will execute when there is no "ul" yet. [note 1] - I tried to add the final two steps into the load() callback, but the LI's were NEVER loaded in the DOM when the callback function was executed.
[Code]....
View 4 Replies
View Related
Mar 16, 2011
I am trying to retrieve json data from the world bank's API, here's my code:
<html>
<head>
<script src="[URL]"></script>
<script type="text/javascript">
var theData;
$(document).ready(function(){
$("button").click(function(){
$.ajax({ url: '[URL]',
success: function(data) {
/*this alert message does not show*/
alert(data);
}, dataType: 'json' });
});
});
</script>
</head>
<body>
<p></p>
<button> Get World Bank Data </button>
</body>
The callback function is not executed but there is response when I checked it using firebug.
View 1 Replies
View Related
Jun 24, 2009
Here is my server side code:
Here is my javascript:
When i call alert(data), it says it is "undefined". i am new to jQuery, but this appears to mean that no data is being passed to the callback function even though i know the $.post() executed properly (the server side code is executing, and the other alert() tells me that it had a successful result and the callback is being made.
View 1 Replies
View Related
Dec 13, 2011
I am trying to use jquery to layout my form elements. I want to make sure that the script is executed after the whole page is loaded. So i put this script insinde my html file in the head section:
<script type="text/javascript">
$(window).load(function(){
var css_attr = {"float": "left" ,"width":180};
[code]....
View 2 Replies
View Related
Aug 20, 2011
I'm trying to scroll/jmp to the #selected div on the current page before it runs the javascript below:
Code:
var hash = window.location.hash.substr(1);
var href = $('.workimg a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #selected';
$('#selected').load(toLoad)
}});
$('.workimg a').click(function(e){
e.preventDefault();
var toLoad = $(this).attr('href')+' #selected';
$('#selected').slideUp(1200,loadContent);
$('#load').remove();
$('#work').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href');
function loadContent() {
$('#selected').load(toLoad,'',showNewContent)
} function showNewContent() {
$('#selected').css("opacity","0");
$('#selected').delay(50).animate({
opacity: 1,
height: 'toggle'
}, 1200, function() {
hideLoader();
});
} function hideLoader() {
$('#load').hide();
}});
How difficult would it be to do this?
View 1 Replies
View Related
Feb 8, 2010
I'm trying to create a scrolling menu. Example here [URL] I don't think there's an issue with the javascript necessarily. I've tried alternatively using jquery's animate function with scrollLeft and I still get the flickering. I'm thinking it's more to do with the HTML/CSS. For instance I'm wondering if using a table instead of a floated list for the menu might be a step in the right direction.
Code PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Gallery</title>
<style type="text/css">
* { /* default styles */
[Code]....
View 10 Replies
View Related
Oct 20, 2011
The javascript served banner is moved from #apple1 to #targetplace. Some times the banner is displayed on both places. Are two page impressions counted for this one page the banner is displayed? Executes the browser the javascript once or each time the javascript is moved?
View 6 Replies
View Related