How to find all the dropped elements in jQuery - javascript

.dropped
{
position: static !important;
}
#dvSource
{
padding: 5px;
min-height: 100px;
width: 470px;
margin-top: 300px;
}
#dvSource img {
padding-left: 10px;
}
.one {
left: 20px;
}
.nodrop {
padding-left: 20px;
}
#dvDest
{
background:url(images/line_background.png);
min-height: 100px;
width: 110px;
float: left;
margin-left: 20px;
}
#dvDest1
{
background:url(images/line_background.png);
display: inline-block;
min-height: 100px;
width: 110px;
margin-left: 10px;
}
#dvDest2
{
background:url(images/line_background.png);
display: inline-block;
min-height: 100px;
width: 110px;
margin-left: 10px;
}
#otherimgs {
float: left;
}
.allcontent {
width: 700px;
margin-top: 120px;
}
.contain {
text-align: center;
}
.contain img {
margin-left: 20px;
}
.popup {
position: absolute;
top: 280px;
right: 480px;
}
.popup img {
width: 435px;
height: 134px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
function hideerror() {
$('.popup').remove();
}
$(function () {
$("#dvSource img.one").draggable({
revert: function () {
$(this).delay(600);
return true
},
revertDuration: 500,
refreshPositions: true,
stop: function (event, ui) {
$("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
}
});
$("#dvSource img.one1").draggable({
revert: function () {
$(this).delay(600);
return true
},
revertDuration: 500,
refreshPositions: true,
stop: function (event, ui) {
$("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
}
});
$("#dvSource img.one2").draggable({
revert: function () {
$(this).delay(600);
return true
},
revertDuration: 500,
refreshPositions: true,
stop: function (event, ui) {
$("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
}
});
$("#dvDest").droppable({
accept: '#dvSource img.one',
drop: function (event, ui) {
if ($("#dvDest img").length == 0) {
$("#dvDest").html("");
}
ui.draggable.addClass("dropped");
$("#dvDest").append(ui.draggable);
$("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
$( this ).hideerror();
}
});
$("#dvDest1").droppable({
accept: '#dvSource img.one1',
drop: function (event, ui) {
if ($("#dvDest1 img").length == 0) {
$("#dvDest1").html("");
}
ui.draggable.addClass("dropped");
$("#dvDest1").append(ui.draggable);
$("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
$( this ).hideerror();
}
});
$("#dvDest2").droppable({
accept: '#dvSource img.one2',
drop: function (event, ui) {
if ($("#dvDest2 img").length == 0) {
$("#dvDest2").html("");
}
ui.draggable.addClass("dropped");
$("#dvDest2").append(ui.draggable);
$("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
setTimeout(function() {
window.location.href = "6.htm";
}, 1500);
$( this ).hideerror();
}
});
});
</script>
<div class="allcontent">
<div id="otherimgs">
<img alt="" src="images/large_ball.png" />
<img alt="" src="images/medium_ball.png" />
<img alt="" src="images/small_ball.png" />
</div>
<div class="contain">
<div id="dvDest"></div>
<div id="dvDest1"></div>
<div id="dvDest2"></div>
</div>
</div>
<div id="dvSource">
<img class="one" alt="" src="images/large_ball.png" />
<img class="one1" alt="" src="images/medium_ball.png" />
<img class="one2" alt="" src="images/small_ball.png" />
</div>
here i have made 3 elements droppable to their respective destination place ..i want to redirect the page to another only when all the 3 elements are dropped in their places..how to find whether the element is dropped.. can anyone help me with this??
check this fiddle for demo http://jsfiddle.net/karthikchandran/stxzqskq/3/

Fiddle Demo
try this
function checked()
{
var i = 0;
if($("#dvDest").children("img").hasClass("dropped"))
{
i++;
}
if($("#dvDest1").children("img").hasClass("dropped"))
{
i++;
}
if($("#dvDest2").children("img").hasClass("dropped"))
{
i++;
}
console.log(i);
if(i ==3)
{
window.location.href="http://google.com";
}
}
create a checked() function and call it on each droppable function
it will get redirected to the given linked as shown in fiddle demo but in fiddle it won't get redirect.

You can use jQuery to count the number of elements that are dropped:
var count = $(".dropped").length;
You can check this and perform an action if the expected number are dropped:
if (count === 3) { ... }

Related

How removing dragged element only if it has a certain class?

I want to remove a dragged element, but it should only be removed when it doesn't have the class "nodrop".
here's my current code it removes all elements wheter i included an if function:
$(".löschen").droppable({
drop: function(event, ui) {
if (!$(this).hasClass("nodrop")){
ui.draggable.remove();
findTotal();
}
}});
I don't have any plan what I've done wrong...
You get the current drop container (.löschen) with $(this). With $(ui.draggable) you get the dropped element with class nodrop.
$(".draggable").draggable();
$(".löschen").droppable({
drop: function(event, ui) {
var $dropContainer = $(this);
var $dragContainer = $(ui.draggable)
console.log($dropContainer, $dragContainer);
if (!$dragContainer.hasClass("nodrop")){
$dragContainer.remove();
}
}});
.draggable {
width: 100px;
height: 100px;
}
.drop {
background-color: green;
}
.nodrop {
background-color: red;
}
.löschen {
width: 200px;
height: 200px;
background-color: #ccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="draggable nodrop">NO DROP</div>
<div class="draggable drop">DROP</div>
<div class="löschen">TRASH</div>

how to set jquery slider on auto instead of click or hover on thumbs

i am new learner of jquery and javaScript.
i want to create a slider with a big image section and a section of thumbs.
slider should slide automatically i have coded so far is working on click or hover but i dont know how to set it on auto please help me how to modify my code. code and slider screen shoot is given below.
slider image
$("document").ready(function()
{
$("#thumbs a").mouseenter(function()
{
var smallimgpath = $(this).attr("href");
$("#bigimage img").fadeOut(function()
{
$("#bigimage img").attr("src",smallimgpath);
$("#bigimage img").fadeIn();
});
return false;
});
});
</script>
#imagereplacement{
border: 1px solid red;
width:98%;
height:400px;
margin:auto;
padding-top:8px;
padding-left:10px;
}
#imagereplacement p{
text-align:inline;
}
#bigimage{
/* border: 1px solid green; */
margin:auto;
text-align:center;
float: left;
}
#thumbs{
/*border: 1px solid yellow;*/
margin: 110px 10px;
text-align:center;
width:29%;
float: right;
}
#thumbs img{
height:100px;
width:100px;
}
//This is where all the JQuery code will go
</head>
<body>
<div id="imagereplacement">
<p id="bigimage">
<img src="images/slider1.jpg">
</p>
<p id="thumbs">
<img src="images/slider1.jpg">
<img src="images/slider2.jpg">
<img src="images/slider3.jpg">
</p>
try with this example, please let me know in case of any more question from you :
$("document").ready(function(){
var pages = $('#container li'),
current = 0;
var currentPage, nextPage;
var timeoutID;
var buttonClicked = 0;
var handler1 = function() {
buttonClicked = 1;
$('#container .button').unbind('click');
currentPage = pages.eq(current);
if ($(this).hasClass('prevButton')) {
if (current <= 0)
current = pages.length - 1;
else
current = current - 1;
nextPage = pages.eq(current);
nextPage.css("marginLeft", -604);
nextPage.show();
nextPage.animate({
marginLeft: 0
}, 800, function() {
currentPage.hide();
});
currentPage.animate({
marginLeft: 604
}, 800, function() {
$('#container .button').bind('click', handler1);
});
} else {
if (current >= pages.length - 1)
current = 0;
else
current = current + 1;
nextPage = pages.eq(current);
nextPage.css("marginLeft", 604);
nextPage.show();
nextPage.animate({
marginLeft: 0
}, 800, function() {});
currentPage.animate({
marginLeft: -604
}, 800, function() {
currentPage.hide();
$('#container .button').bind('click', handler1);
});
}
}
var handler2 = function() {
if (buttonClicked == 0) {
$('#container .button').unbind('click');
currentPage = pages.eq(current);
if (current >= pages.length - 1)
current = 0;
else
current = current + 1;
nextPage = pages.eq(current);
nextPage.css("marginLeft", 604);
nextPage.show();
nextPage.animate({
marginLeft: 0
}, 800, function() {});
currentPage.animate({
marginLeft: -604
}, 800, function() {
currentPage.hide();
$('#container .button').bind('click', handler1);
});
timeoutID = setTimeout(function() {
handler2();
}, 4000);
}
}
$('#container .button').click(function() {
clearTimeout(timeoutID);
handler1();
});
timeoutID = setTimeout(function() {
handler2();
}, 4000);
});
* {
margin: 0;
padding: 0;
}
#container {
width: 604px;
height: 453px;
position: relative;
}
#container .prevButton {
height: 72px;
width: 68px;
position: absolute;
background: url('http://vietlandsoft.com/images/buttons.png') no-repeat;
top: 50%;
margin-top: -36px;
cursor: pointer;
z-index: 2000;
background-position: left top;
left: 0
}
#container .prevButton:hover {
background-position: left bottom;
left: 0;
}
#container .nextButton {
height: 72px;
width: 68px;
position: absolute;
background: url('http://vietlandsoft.com/images/buttons.png') no-repeat;
top: 50%;
margin-top: -36px;
cursor: pointer;
z-index: 2000;
background-position: right top;
right: 0
}
#container .nextButton:hover {
background-position: right bottom;
right: 0;
}
#container ul {
width: 604px;
height: 453px;
list-style: none outside none;
position: relative;
overflow: hidden;
}
#container li:first-child {
display: list-item;
position: absolute;
}
#container li {
position: absolute;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<center>
<h1>HTML Slideshow AutoPlay (Slide Left/Slide Right)</h1>
<br />
<br />
<div id="container">
<ul>
<li><img src="http://vietlandsoft.com/images/picture1.jpg" width="604" height="453" /></li>
<li><img src="http://vietlandsoft.com/images/picture2.jpg" width="604" height="453" /></li>
<li><img src="http://vietlandsoft.com/images/picture3.jpg" width="604" height="453" /></li>
</ul>
<span class="button prevButton"></span>
<span class="button nextButton"></span>
</div>
</center>
Here an example i've created that create an auto slider CodePen Demo and JSFiddle Demo
I've used an object literal pattern to create slide variable just to avoid creating many global function and variable. Inside document.ready i've initialised my slider just by calling slide.init({....}) this way it makes it easy to reuse and work like plugin.
$.extend(slide.config,option)
this code in simple words override you're default configuration defined in config key
as i mentioned in my above comment make a function slider() and place seTimeout(slide,1000) at bottom of your function before closing
Here in this code its done in animate key of slide object it is passed with two parameter cnt and all image array, If cnt is greater then image array length then cnt is set to 0 i.e if at first when cnt keeps on increment i fadeout all image so when i make it 0 the next time the fadeToggle acts as switch
if On then Off
if Off the On
and calling function slider after a delay makes it a recursive call its just one way for continuously looping there are many other ways i guess for looping continuous you can try
well i haven't check if all images Loaded or not which is most important in slider well that you could try on your own.
var slide = {
'config': {
'container': $('#slideX'),
'delay': 3000,
'fade': 'fast',
'easing': 'linear'
},
init: function(option) {
$.extend(slide.config, option);
var imag = slide.getImages();
slide.animate(0, imag);
},
animate: function(cnt, imag) {
if (cnt >= imag.length) {
cnt = 0;
}
imag.eq(cnt).fadeToggle(slide.config.fade, slide.config.easing);
setTimeout(function() {
slide.animate(++cnt, imag);
}, slide.config.delay);
},
getImages: function() {
return slide.config.container.find('img');
}
};
$(document).ready(function() {
slide.init({
'contianer': $('#slideX'),
'delay': 3000,
'fade': 'fast',
'easing': 'swing'
});
})
body {
margin: 0;
padding: 0;
}
.contianer {
width: 100%;
height: 100%;
position: relative;
}
.container > div,
.container > div >img {
width: 100%;
height: 100%;
position: absolute;
z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container" id="slideX">
<div id="img1">
<img src="http://imgs.abduzeedo.com/files/articles/magical-animal-photography-gregory-colbert/5.jpg" />
</div>
<div id="img2">
<img src="http://cdn-5.webdesignmash.com/trial/wp-content/uploads/2010/10/great-dog-photography-016.jpg" />
</div>
<div id="img3">
<img src="http://onlybackground.com/wp-content/uploads/2014/01/marble-beautiful-photography-1920x1200.jpg" />
</div>
</div>

simple fade javascript image rotator

I found this old post asking for a simple fade image rotator:
Looking for a simple fade javascript image rotator
and found what I was looking for:
$(function() {
$('#fader img:not(:first)').hide();
$('#fader img').css('position', 'absolute');
$('#fader img').css('top', '0px');
$('#fader img').css('left', 'auto');
$('#fader img').css('right', 'auto');
//$('#fader img').css('left', '50%');
$('#fader img').each(function() {
var img = $(this);
$('<img>').attr('src', $(this).attr('src')).load(function() {
//img.css('margin-left', -this.width / 2 + 'px');
});
});
var pause = false;
function fadeNext() {
$('#fader img').first().fadeOut().appendTo($('#fader'));
$('#fader img').first().fadeIn();
}
function fadePrev() {
$('#fader img').first().fadeOut();
$('#fader img').last().prependTo($('#fader')).fadeIn();
}
$('#fader, #next').click(function() {
fadeNext();
});
$('#prev').click(function() {
fadePrev();
});
$('#fader, .arwBtn').hover(function() {
pause = true;
},function() {
pause = false;
});
function doRotate() {
if(!pause) {
fadeNext();
}
}
var rotate = setInterval(doRotate, 4000);
});
this was the original fiddle
http://jsfiddle.net/jtbowden/UNZR5/1/
I have already spent some time adapting it (not a jquery programmer :/)
And all I need to add are captions to each picture.
Can someone help me just add captions to that same code?
Really appreciate it : )
You will need to enhance CSS more than this, but it is working as requested
http://jsfiddle.net/dU93C/
CSS
#fader {
position: relative;
width:500px;
height: 400px;
}
#fader div{
position: relative;
height: 400px;
width:400px;
overflow:hidden;
margin:0 auto;
}
#fader strong{
display:block;
position: absolute;
width:100%;
top:0;
left:0;
Background:#333;
Color:#fff;
padding:5px;
opacity:0.7;
filter:alpha(opacity=70);
}
.button {
background-color: green;
width: 50px;
height: 30px;
font-size: 20px;
line-height: 30px;
text-align: center;
position: absolute;
top: 30px;
}
#next {
right: 0;
}
#prev {
left: 0;
}
HTML
<div id="fader">
<a class="button" href="#" id="next">Next</a>
<a class="button" href="#" id="prev">Prev</a>
<div>
<strong>Image 1</strong>
<img src="http://dummyimage.com/600x400/000/fff.png&text=Image1"/>
</div>
<div>
<strong>Image 2</strong>
<img src="http://dummyimage.com/200x400/f00/000.jpg&text=Image2"/>
</div>
<div>
<strong>Image 3</strong>
<img src="http://dummyimage.com/100x100/0f0/000.png&text=Image3"/>
</div>
<div>
<strong>Image 4</strong>
<img src="http://dummyimage.com/400x400/0ff/000.gif&text=Image4"/>
</div>
<div>
<strong>Image 5</strong>
<img src="http://dummyimage.com/350x250/ff0/000.png&text=Image5"/>
</div>
</div>
JS
$(function() {
$('#fader div:not(:first)').hide();
var pause = false;
function fadeNext() {
$('#fader div').first().fadeOut().appendTo($('#fader'));
$('#fader div').first().fadeIn();
}
function fadePrev() {
$('#fader div').first().fadeOut();
$('#fader div').last().prependTo($('#fader')).fadeIn();
}
$('#fader, #next').click(function(e) {
fadeNext();
e.preventDefault()
});
$('#prev').click(function() {
fadePrev();
});
$('#fader, .button').hover(function() {
pause = true;
},function() {
pause = false;
});
function doRotate() {
if(!pause) {
fadeNext();
}
}
var rotate = setInterval(doRotate, 2000);
});

How to Animate (slide) content adjacent to content with jquery toggle()

I am setting up a page which the user can hide the side bar if they wish. I am trying to use the jqeuryui to do this with the following js code
// TOGGLE JS
$(function () {
function runEffect() {
var options = {};
$("#effect").toggle('slide', options, 500);
};
$("#button").click(function () {
runEffect();
return false;
});
});
I have this working in a JSFiddle here http://jsfiddle.net/jwg4U/
However, when you look at the JSFiddle you will notice that my main content area which is a DIV called #content does not animate, it just jumps into place when I toggle the sidebar.
I would like the content div to also slide into place seamlessly and follow the toggle as it if it attached to it.
I have looked at jquery animate, but not sure how to implement this with the slide?
A Second part I am struggling with is how to change the button text when the sidebar is closed to say "Show Sidebar" - Weather it is open or closed right now it just says "Hide Sidebar"
Looking for some help
Thanks
See this updated fiddle : http://jsfiddle.net/jwg4U/23/
HTML:
<div id="container" style="width:800px">
<div id="header">
<h1>HEADER</h1>
</div>
<div class="toggler">
<div id="effect" class="ui-widget-content ui-corner-all">
<div id="menu" style="background-color:#FFD700;height:300px;width:100px;float:left;">
<h3>SIDEBAR</h3>
</div>
</div>
<div id="content" style="background-color:#EEEEEE;height:300px;">Main Content goes here</div>
</div>
Hide Sidebar
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
FOOTER</div>
</div>
​
JS:
// TOGGLE JS
$(function() {
var i = 0;
function runEffect() {
var options = {};
if (i === 0) {
i = 1;
$(".toggler").animate({
left: -100
}, {
duration: 500
});
}
else {
i = 0;
$(".toggler").animate({
left: 0
}, {
duration: 500
});
}
}
$("#button").click(function() {
if (i === 0) {
$(this).html("Show Sidebar");
}
else {
$(this).html("Hide Sidebar");
}
runEffect();
return false;
});
});
// TABS JS
$(function() {
$("#tabs").tabs();
});​
CSS:
.toggler {
float: left;
position: relative;
}
#button {
padding: .5em 1em;
text-decoration: none;
}
#effect {
position: relative;
float: left;
}
#content{
position: relative;
float: left;
width: 500px;
}
#button{
float: left;
clear: both;
}
#header{
background-color: #000;
color: #FFF;
}​
The jsfiddle for the complete answer : http://jsfiddle.net/jwg4U/22/
$('#effect').animate({
width: 'toggle',
height: 'toggle'
}, {
duration: 500,
specialEasing: {
width: 'linear',
height: 'linear'
},
complete: function() {
$("#content").animate(
{ left: '+=100px' },
60,
'easeInQuad',
function ()
{
if(isOpen)
{
isOpen=false;
$("#button").html('Show Sidebar');
}
else
{
isOpen=true;
$("#button").html('Hide Sidebar');
}
});
}
});

jQuery window.load doesn't modify dom elements created with other javascript

Im using jQuery to modify html that has been created with other javascript. If I make the jQuery run when I click a button everything works fine.
However if I run the jQuery on window load it doesn't do anything. By adding an alert it seems its run before the other javascript has finished created html on the page. How can I make my jQuery run after all other javascript has finished?
Note - im making a demo only, so performance and best practice aren't really an issue in this case. Thanks
UPDATE - here is my code:
<html>
<head>
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="../gmap3.js"></script>
<style>
body, html {
margin: 0;
padding: 0;
}
.gmap3{
margin: 20px auto;
border: 1px dashed #C0C0C0;
width: 320px;
height: 450px;
}
#panTo{
background-color: Pink;
float: left;
text-align: left;
width: 200px;
}
.find {
height: 10px;
width: 10px;
background-color: grey;
}
#start {
position: absolute;
top: 0;
right: 0;
}
#button-0 {
display: none;
}
.two {
background-color: white;
display: none;
white-space: nowrap;
z-index: 999999;
position: relative;
right: -19px;
top: -46px;
padding: 5px;
border: 1px solid black;
border-radius: 10px;
}
.no {
text-align: center;
border:1px solid grey;
position: relative;
left: -22px;
top: -2px;
background-color: white;
width: 19px;
height: 32px;
}
.active {
font-weight: bold;
}
</style>
<script type="text/javascript">
$(function(){
var points = [
[54.618017, 3.48291],
[53.618017, 2.78291],
[52.618017, 2.48291],
[51.618017, 2.28291],
[50.618017, 1.88291],
[50.218017, 1.48291],
[50.118017, 0.439453]
];
$('#test1').gmap3(
{ action: 'init',
center:{
lat:44.797916,
lng:-93.278046
},
onces: {
bounds_changed: function(){
$(this).gmap3({
action:'getBounds',
callback: function (bounds){
if (!bounds) return;
var southWest = bounds.getSouthWest(),
northEast = bounds.getNorthEast(),
lngSpan = northEast.lng() - southWest.lng(),
latSpan = northEast.lat() - southWest.lat(),
i;
for (i = 1; i < 4; i++) {
// add($(this), i, southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
add($(this), i, points[i][0], points[i][1]);
}
}
});
}
}
}
);
});
function add($this, i, lat, lng){
$this.gmap3(
{ action: 'addMarker',
latLng: [lat, lng],
callback: function(marker){
var $button = $('<span id="button-'+i+'"> ['+i+'] </span>');
$button
.click(function(){
$this.gmap3({
action:'panTo',
args:[marker.position]
});
})
.css('cursor','pointer');
$('#panTo').append($button);
}
},
{ action:'addOverlay',
latLng: [lat, lng],
options:{
content: '<div class="no no-'+i+'" >'+i+'<div class="two"></div></div>',
offset:{
y:-32,
x:12
}
},
events:{
mouseover: function(overlay){
// $(overlay.getDOMElement()).children().css('backgroundColor', '#0000FF');
},
mouseout: function(overlay){
// $(overlay.getDOMElement()).children().css('backgroundColor', '#00FF00');
}
}
});
}
$(document).ready(function() {
//$('#start').live("click", function() {
// $(window).load(function () {
$('#button-1').html('<p>1) Herne Hill</p>');
$('#button-2').html('<p>2) Sloane Square</p>');
$('#button-3').html('<p>3) Elephant and Castle</p>');
$('.no-1 .two').text('Herne Hill');
$('.no-2 .two').text('Sloane Square');
$('.no-3 .two').text('Elephant and Castle');
$('#button-1').live("click", function() {
$('.two').css('display','none');
$('.no-1 .two').css('display','inline-block');
$('#panTo span').removeClass('active');
$(this).addClass('active');
});
$('#button-2').live("click", function() {
$('.two').css('display','none');
$('.no-2 .two').css('display','inline-block');
$('#panTo span').removeClass('active');
$(this).addClass('active');
});
$('#button-3').live("click", function() {
$('.two').css('display','none');
$('.no-3 .two').css('display','inline-block');
$('#panTo span').removeClass('active');
$(this).addClass('active');
});
$('.no-1').live("click", function() {
$('.two').css('display','none');
$('.no-1 .two').css('display','inline-block');
$('#panTo span').removeClass('active');
$('#button-1').addClass('active');
});
$('.no-2').live("click", function() {
$('.two').css('display','none');
$('.no-2 .two').css('display','inline-block');
$('#panTo span').removeClass('active');
$('#button-2').addClass('active');
});
$('.no-3').live("click", function() {
$('.two').css('display','none');
$('.no-3 .two').css('display','inline-block');
$('#panTo span').removeClass('active');
$('#button-3').addClass('active');
});
});
</script>
<meta name="viewport" content="width=device-width">
</head>
<body>
<div id="start">start</div>
<div id="panTo"></div>
<div id="test1" class="gmap3"></div>
</body>
</html>
You may also delay the execution of your script to make sure other libraries have completed their initialization.
Eg:
$(function(){
setTimeout(function(){
//your code in this block is executed after 500 ms
}, 500);
});
If you place your code after the external code, it will run after the external code is finished, because ready handlers uses a queue.
There is no reason to use setTimeout
$(function(){alert('external');});
//...
//...
//...
$(function(){alert('your code');});​
see this DEMO

Categories

Resources