I'm developing a plugin for a website building program, and am building the preview page for it. It's sort of a parallax scrolling plugin and the issue I'm having is that in Safari, when you scroll down to a certain point, it wont allow you to scroll any further. It's fine in firefox and chrome, but I saw the same issue in opera. I've managed to narrow it down to the function that's causing it, but I have no idea why or how to fix it.
When I comment out this function, the page scrolls fine, but it doesn't remove the empty divs like I need it to do:
function removeStuff() {
$('.conP').each(function(){
var divDad = $(this),
divses = $(this).children();
if (divses.hasClass('empty'))
divDad.remove();
});
}
here's the preview page where the issue can be observed:
http://reveriesrefined.com/myftp/dack_stev/
//////////EDIT:
I've simplified the code to this:
$('.conP_%id% > .empty').parent().remove();
however, it's still causing scrolling issues in safari and opera, but not the other browsers.
Any help is VERY VERY appreciated!
Actually, I found the issue already. Somehow even though commenting out the function mentioned above seemed to solve it, it was actually a line of code in another function.
I had this function:
function autoPlay() {
var backDiv = $('#outterLax div:first');
backDiv.hide();
$('.conP').hide();
backDiv.remove();
$('#outterLax').append(backDiv);
backDiv.show();
}
but the line:
$('.conP').hide();
was unnecessary as that was already being accomplished elsewhere in my code.
Related
so I have a webpage which should work on both desktop and mobile devices. I'm having quite a bit of trouble making the buttons work, however.
This is how a button looks like:
<a class="button" id="upload-media-button" onclick='uploadMedia();'>Upload</a>
And this is the uploadMedia code:
var uploadMedia = function() {
if(!isUploadFormVisible){
alert(isUploadFormVisible);
event.preventDefault();
event.stopPropagation();
dropperForm = document.getElementById("upload-form");
dropperForm.className = '';
isUploadFormVisible = 1;
$("body").addClass("modal-open");
} else {
alert(isUploadFormVisible);
event.preventDefault();
dropperForm = document.getElementById("upload-form");
dropperForm.className = 'hidden';
isUploadFormVisible = 0;
$("body").removeClass("modal-open");
refreshMedia(true);
}
}
The funny thing is that the buttons work fine on desktop and it partially works on mobile as well (if instead of onclick='uploadMedia(); I do onclick='alert(whatever); the alert is displayed successfully). I've spent most of yesterday and today trying to fix the issue, but it is simply not working.
I've tried something like this as well:
$(document).ready(function() {
$('#upload-media-button').on('click touchstart', function(){
dropperForm = document.getElementById("upload-form");
dropperForm.className = '';
isUploadFormVisible = 1;
$("body").addClass("modal-open");
});
}
And this still doesn't work.
Edit:
Even though the answer helped me fix the issue, it was only a momentary fix: this was absolutely unbelievable and I was really confused on how to make those damn buttons work. I had tried everything.
By investigating the issue, I found out that this problem never appeared on desktop (with both static file compression off and on), however, on mobile, compression did make a difference as without it it worked fine.
The conclusion to this investigation is clear: check your code for syntax errors. I was missing maybe a dozen semicolons and the console didn't complain whatsoever (in fact it worked ok on desktop w/ compression).
Anyways, if you use compression like me, make sure to grab the source from the compressed file and run it through JSHint (or whatever works for you), to check for syntax errors.
Now I get why people hate JS.
An <a> tag with no href attribute is not a tap target for touchscreens.
Add href="#" (with a suitable event.preventDefault(); call) or href="javascript:void(0);" to make it an actual, clickable (tappable) thing.
I've been working on a project for work where I need to create a Javascript "jump-menu" within a page.
(Q:Wait, a jump-menu? Why don't you just use a elements and namespaces to navigate within your page?
A: Because that would defeat the purpose! So please, don't provide answers like that. I need to do this with Javascript (AND I'M NOT USING JQUERY!!!))
So, here is what I do:
I make a list at the top of the page, and a list at the bottom of the page.
I add an event listener to each list item at the top of the page and I attach a reference to that list items corresponding content item within the page.
When the link at the top is clicked, I grab to offsetTop of the item I want to scroll to, and I set either the document.body.scrollTop or the window.pageYOffset.
I've never actually needed the window.pageYOffset, but somewhere told me it would work and I never removed it from my code. Either way, this appears to work with the document.body.scrollTop in Chrome, Safari, and Opera, yet it doesn't work in Firefox or IE. Why?
Here is the code block where I set the document.body.scrollTop:
if(elem.jump_ref)
{
if(document.body.scrollTop || document.body.scrollTop === 0)
{
document.body.scrollTop = elem.jump_ref.offsetTop - page_top_padding;
}
else if(window.pageYOffset || window.pageYOffset === 0)
{
window.pageYOffset = elem.jump_ref.offsetTop - page_top_padding;
}
}
And Heres The Project In JSFIDDLE
I've stepped through and found that "Yes, I am grabbing the right element." and "Yes, I am setting the document.body.scrollTop, and "No, I am not setting the document.body.scrollTop to zero." and yet it still doesn't work! Please help! My webpage is supposed to go public on Tuesday!
Well, I believe I have found my answer. So far, it appears to work in Chrome, Firefox, IE, Opera, and Safari (these were the only ones I was able to test). I don't know what type of mobile support this feature will have (if any), but my page already has an entirely different functionality for mobile anyway.
Either way, here's the fix. Its the window.scrollTo method!:
this.jump = function(evt)
{
var elem = evt.srcElement || evt.currentTarget;
var page_top_padding = 100;
if(elem.jump_ref)
{
window.scrollTo(0, (elem.post_ref.offsetTop - page_top_padding));
}
}.bind(this);
And like I said, it works great in nearly everything! Everything except JSFiddle. lol. I don't quite get it, but luckily no one is going to be visiting my webpage in JSFiddle.
I am simply trying to change the SRC attribute of an image via javascript like so:
document.getElementById('fooImage').src = img;
Where img is a variable that has a link to the file.
In all other browsers (Chrome, Firefox, Safari) this works. In IE (7+) this also works too sometimes.
Using IE's built-in developer tools, I can see that the image's SRC tag is set. Is there something else in the locals window that could help me debug why the image doesn't actually show on screen?
I've also tried using jQuery to do this and same outcome:
$("#fooImage").attr("src", img);
An ideas?
In debugging this I would hard code it first...
document.getElementById('fooImage').src = "myimage.png";
I've used the following in my website and it works like this...
var imgCounter = document.getElementById('formtimer');
imgCounter.src = "graphics/odometers/1.png";
Some other things to check:
Make sure your ID= tag is not in the <DIV section but inside the <IMG section... for example <div class="style1"><img src="yourpicture" id="someid">. If `id='someid' is in the div tag then you can't change the picture / the picture won't show up.
are you using window.onload?, body onload? the proper way to use the first is..
window.onload = function () { YourFunctionHere(); };
Try a different test image. I had issues in the past with showing png's, I changed it to a gif or jpg and it worked. I don't understand how that was "way back" but it doesn't seem to be an issue anymore but hey... something to try.
try a full url
using https?
try sticking the image somewhere else in your program and see what happens.
try adding this to your HTML (put your website in place of mine - lookup BASE href on google for more info)
<BASE href="http://perrycs/" />
Make sure the image isn't hidden behind a layer (I know it works in some browsers)
tell us the website so we can check it out and get more info to help you in debugging this, seeing context (surrounding code) helps...
Given that it works in other browsers, searching on this topic it seems that often the problem is how IE caches images (ref. Epascarello's comment). Your code is the same as what I have - it works fine except in IE10.
I too, faced this conundrum. Then discovered that it works in 'Page Inspector', so after some digging discovered that (in Internet Explorer) by going to Tools.Internet Options.Advanced
uncheck the 'Disable script debugging (Internet Explorer)' and the one below it.
I found that with IE9 after changing an image.src with
var strVar="C:Users/x/Desktop/caution.png"
image.src=strVar
and calling an alert(image.src) I would get something like this n the alertbox:
file:///C:Users/x/Desktop/"C:Users/x/Desktop/caution.png"
So I tried
image.src=strVar.replace(/\"/g,"")
to remove qoutemarks
and it worked!
alert(image.src)
file:///C:Users/x/Desktop/caution.png
I have this most annoying issue with removeClass in Firefox.
I am using it to change some of the elements on the page so that when I resize my player the layout looks good. I am using JW player API to resize the player using the jQuery click method, then it starts playing automatically or from the position it was at.
Now all of that works perfectly in IE (surprising), Chrome, Opera, Safari. It's seemless with no hiccup. But Firefox will reinitialize the player and it starts over. I have a removeClass that I perform on a div that surrounds the player. If I take that out, Firefox does what it's supposed to do. I have to use the removeClass to realign my layout. It works fine with addClass, just not with removeClass.
Any ideas why it won't work with removeClass() properly?
Below is my code how I want it to work and it does for EVERY browser but FF.
jQuery(document).ready(function(){
jQuery("#expand").live("click",function(event){
var time = jwplayer().getPosition();
var cont = $('#lcontents').html();
$('#tleft').html(cont);
$('#pleft').addClass("centerText videoWide");
$('#pleft').removeClass("column-video-left");
$('#lcontents').html("");
$('#tleft').addClass("column-video-left");
jwplayer().resize("854","480");
if(time > 0){
jwplayer().onReady(function() {
jwplayer().seek(time);
});
}else if(time < 1){
jwplayer().play();
};
event.preventDefault();
});
});
Edit- The code below is the html
<div id="pleft" class="column-video-left">
<div id="rsplayer" class="video">jwplayer code renders here</div>
<div id="expand" style="text-align:center">Expand Player</div>
<div id="lcontents">
regular html code here.... which gets moved to div tleft
</div>
</div>
<div id="expand1"></div>
<div id="tleft"></div>
Have you tried manually modify the class attribute and seeing if that works?
It's possible this is a known bug in Firefox 3.6. You could try it in the Firefox 4 release candidate and see if you still have the same problem. If you don't, then someone who's good at doing Bugzilla searches could figure out what the bug was, and whether the fix will be backported to the 3.6 branch.
I'm presenting a simple animation using img.src replace and the <canvas> tag. At present it's only expected to work in FireFox (FF 3.5.3, Mac OS X 10.5.5), so cross-browser compatibility isn't (yet) an issue.
When the page is first loaded, or loaded into an new window or tab, all seems to work as expected, and the cache behavior on a simple reload does not seem to be an issue; however, if I try to force a reload with shift-reload, I get a problem. Even though the images have been pre-loaded, the preloaded images for the animation don't seem to be available to the browser which then tries to load each new img.src from the server.
Am I looking at a browser bug here, or is there something buggy in my code that I can't see? This is my first shot at implementing a js class, so there might be a lot here that I don't understand.
Any insight from the assembled wise here would be welcome. You can see what I'm talking about at:
http://neolography.com/staging/mrfm/spin-sim.html
Thanks,
Jon
When you shift reload you're telling the browser to reload - not from the cache.
So it shouldn't be a surprise that you're getting the images from the server.
Images can be preloaded in javascript with the following code:
img = new Image();
img.src = "your/image/path";
If you want the images loaded before you use them that might help.
I had a look at your code and you have the following in document.ready()
function countLoadedImages() {
loadedImgs++;
if (loadedImgs == images.length){
$("#loading-image").hide();
$("#controls").fadeIn(100);
}
}
animation = new simAnim("snap", "stripchart", 800, deriveFrameData(spindata));
the animation = new simAnim line is executed regardless if all 100 images are loaded or not...
One possibility to fix this would be to move that line inside the countLoadedImages function like so:
function countLoadedImages() {
loadedImgs++;
if (loadedImgs == images.length){
$("#loading-image").hide();
$("#controls").fadeIn(100);
animation = new simAnim("snap", "stripchart", 800, deriveFrameData(spindata));
}
}
this way that function will be executed once all the images have loaded
Thanks to ekhaled, who tried. I'm now satisfied that this is a browser bug:
Mozilla bug #504184
I have a stripped down example at http://neolography.com/staging/shift-reload/shift-reload-testcase.html which I will leave up. I encourage all to vote for this bug in the mozilla bug tracker so that it will get fixed.
j