$(".test").click(function(event) {
event.preventDefault();
var self = this;
$("#preloader #image").fadeIn();
$("#preloader").fadeIn();
$(".frame").load(self.href,function() {
$("#preloader #image").fadeOut();
$("#preloader").delay(111).fadeOut();
$(".content").slideToggle(185);
});
});
This should slideToggle after load content of div('.frame'), but content slide instantly, also content appear faster than preloader fadeOut. Why is this happening?
Related
I'd like to hide my page's navigation when video is playing, just like the play button does.
Here's the script that succesfully hides the play button:
<script>
$('.vid').parent().click(function () {
if($(this).children(".vid").get(0).paused){
$(this).children(".vid").get(0).play();
$(this).children(".playpause").fadeOut();
}else{
$(this).children(".vid").get(0).pause();
$(this).children(".playpause").fadeIn();
}
});
</script>
And this script I tried to hide my navigation bar with:
<script>
function vidplay() {
var video = document.getElementById(".vid");
var button = document.getElementById(".playpause");
if (video.paused) {
video.play();
$(".navbar").hide();
</script>
Here's link to my site
Try using the jQuery .toggle() function;
$('.vid').parent().click(function () {
$(".navbar").toggle();
});
You didn't close your function and if statement
<script>
function vidplay() {
var video = document.getElementById(".vid");
var button = document.getElementById(".playpause");
if (video.paused) {
video.play();
$(".navbar").hide();
}
}
</script>
I have a code, which gets refreshed from mysql database on a button click.
From the mysql I get links of images on refresh, but I never know, hat links and how many.
I have a "loading" circle which spins until the page is loaded, but it is shown only, until the code is loaded, which is not very long. After that I see small empty squares on my page as placeholders, until the real images show up.
Does anybody have an idea, how to show the spinning circle untill all images are loaded?
I tried some javascript examples found on the net with building arrays of links, but I was not able to integrate them into my code, because the construction of the codes are very different and I obviously am not a pro.
So here is my code (I simplified it for now):
$(document).ready(function() {
function refresh(free){
$("#loadingfree").show();
if (free) datum = datum + free;
var url = "listfree.php?date=" + datum;
$.getJSON(url,function(data) {
var div_data = '';
$.each(data, function(i,data) {
div_data += "<div class='iconsfree'><a href='"+data.title+"-"+data.appID+"' title='"+data.title+"'><img src='"+data.icon+"'></img></a></div>";
});
$("#loadingfree").hide();
$("#app-wrapper-free").html(div_data);
});
}
$(document).on('click', '#prevbuttonfree', function(e){
e.preventDefault();
$("#app-wrapper-free").empty();
refresh(-1);
});
$(document).on('click', '#nextbuttonfree', function(e){
e.preventDefault();
$("#app-wrapper-free").empty();
refresh(+1);
});
// call the method when page is opened:
refresh(0);
});
If you want the spinner to continue showing until the images are loaded, you should use the load eventListener to make that happen.
So let's say you have your code that has the spinner while it makes the request to the server.
//just an example
$('button').click(function(){
//call server
$.ajax();
//show spinner
$('.spinner').show();
});
Now we will tell the spinner to stay showing until the images are done loading.
$('img').on('load',function(){
//Not sure what your spinner is called
$('.spinner').hide();
});
I ended up with this.
It just shows the content a bit later. It's a fake preloader.
<script type="text/javascript">
var datum = 0;
$(document).ready(function() {
function refresh(free){
if (free) datum = datum + free;
var url = "listfree.php?date=" + datum;
$.getJSON(url,function(data) {
var div_data = '';
$.each(data, function(i,data) {
if ($("#date_free").html() == '');
div_data += "<div class='iconsfree'><a href='"+data.title+"-"+data.appID+"' title='"+data.title+"'><img src='"+data.icon+"'></img></a></div>";
});
$("#loadingfree").show();
$(div_data).hide()
.appendTo("#app-wrapper-free")
setTimeout( function() {
$("#app-wrapper-free").children().show()
$("#loadingfree").hide()
}, 3000 );
});
}
$(document).on('click', '#prevbuttonfree', function(e){
e.preventDefault();
$("#app-wrapper-free").empty();
refresh(-1);
});
$(document).on('click', '#nextbuttonfree', function(e){
e.preventDefault();
$("#app-wrapper-free").empty();
refresh(+1);
});
// call the method when page is opened:
refresh(0);
});
</script>
$(document).ready(function(){
$('#container').load('contents/home.html');
$('#nav ul#navigation li a').click(function(){
var page = $(this).attr('href');
$('#container').fadeOut('slow').load('contents/' + page + '.html').fadeIn('slow');
return false;
});
});
This works good when loading pages within a div container.
home.html containing nivoSlider, when the whole page is refreshing it works good but loading home.html again onto #container after loading pages using function
$('#container').load('contents/' + page + '.html') then the nivoSlider isn't not working.
I have to refresh the whole page just to refresh the div. So I need a code to refresh the div every time it load the pages onto the div #container.
Make sure to encapsulate unique knowledge in a single place in your code. If you need to refresh something, make sure to put this in a single place and then call it as required. Your code could look something like this:
$(document).ready(function() {
var container = $('#container');
function loadContent(url, callback) {
return container.load(url, {}, function () {
// Add code here to refresh nivoSlider
// Run a callback if exists
if (callback) {
callback();
}
});
}
loadContent('contents/home.html');
$('#nav ul#navigation li a').click(function (event) {
var page = $(this).attr('href');
container.fadeOut('slow').loadContent('contents/' + page + '.html').fadeIn('slow');
event.preventDefault();
});
});
On my website, I catch clicks on links to load the content of that page dynamically using AJAX. This new content may require some CSS file that isn't loaded yet. Setting the content of the target element to the response HTML will automatically load the required CSS (the <link> tags are there), but the content will look messed up for a brief period until the CSS gets loaded.
Other than loading all CSS files in advance, what can I do to prevent this? For completeness sake, here is my code:
$(document).ready(function() {
$('a').live('click', function(event) {
if (this.target || this.rel == 'ignore' || this.rel == 'fancybox') {
return true;
}
if (/^javascript:/.test(this.href)) {
return true;
}
if (this.href.indexOf('#') >= 0) {
return false;
}
if (!this.href) {
return true;
}
loadDynamicPage(this.href);
event.preventDefault();
return false;
});
});
var currentLoader = null;
function loadDynamicPage(url) {
if (currentLoader) {
currentLoader.abort();
currentLoader = null;
}
$('#backButton').addClass('loaderBG');
currentLoader = $.ajax({
context: $('#army_content'),
dataType: 'text',
url: url + '&format=raw',
success: function(data) {
currentLoader = null;
$('#backButton').removeClass('loaderBG');
clearRoomIntervals();
$(this).html(data).find('[title]').tooltip({
showURL: false,
track: false,
delay: 300
});
$(document).trigger('dynamicLoad');
}
});
}
Click on the link, show "Loading.."
Load CSS file by ajax, in callback function, create <style> tag, and then insert CSS code to <style> tag, and then start load content by ajax.
*you can optimize the flow by load CSS and content individually, but content only take place in a hidden container, once CSS file finish load, then change hidden container to be shown.
Hope it helps.
Could anyone tell my what am I doing wrong? The problem is that i have links that opens in iframe, and I want this iframe to be opened with Slide effect after I click the links (and after content will load to iframe). This is my code:
JS:
window.addEvent('domready', function(){
var mySlide = new Fx.Slide('slider').hide();
$$('.cal_titlelink').addEvent('click', function(e) {
e = new Event(e);
mySlide.slideIn();
e.stop();
});
});
HTML:
<a class="cal_titlelink" target="details" href="//address is created dynamically by php//">Link 1</a>
<a class="cal_titlelink" target="details" href="//address is created dynamically by php//">Link 2</a>
....
<div id="slider"><iframe name="details"></iframe></div>
Here you can see how it works http://wisko.pl/ It's a calendar on the left. Slide effect works but iframe is empty. When i remove slider then iframe loads but with no effect. How can i make to load iframe content with slide effect? Please help.
http://jsfiddle.net/ZJzjV/114/
var mySlide = new Fx.Slide('slider').hide(),
myFrame = $('myFrame');
$$('.cal_titlelink').addEvent('click', function(e) {
myFrame.innerHTML = '';
e = new Event(e);
mySlide.hide();
e.stop();
if (!myFrame.getProperty("src")) {
myFrame.addEvent("load", function() {
mySlide.slideIn();
console.log("loaded");
});
}
myFrame.setProperty('src',this.getProperty('href'));
});
this is updated to work by adding a load event once and will slide it in once the iframe is loaded.