I will not go into details because it is very well documented here: Position: fixed element in position: relative parent. Which browser displays correctly?
The main problem is how browsers handle position:fixed; elements position:fixed; .
To solve this problem, use position: relative; in #pBrush LESS.
#pBrush { width: 24px; height: 34px; background: transparent url('../images/paintBrush.png') left bottom no-repeat; position: relative; .color { position: absolute; width: 12px; height: 12px; border: 1px solid
And in your JavaScript, adjust based on the offset of your canvas
pBucketHTML.css('left', e.pageX - $("#canvasBuilder").offset().left - (pBucketHTML.width() / 2));
You may need to adjust this a bit, but I believe that this is what you are looking for.
Edit: In case the hacking work for Safari 8 is acceptable, adapted from How to determine my browser version and operating system using JavaScript? :
function returnSafariOffset() { var nAgt = navigator.userAgent; // We have Safari if ((verOffset=nAgt.indexOf("Safari"))!=-1) { fullVersion = nAgt.substring(verOffset+7); if ((verOffset=nAgt.indexOf("Version"))!=-1) { fullVersion = nAgt.substring(verOffset+8); } majorVersion = parseInt(''+fullVersion,10); if (isNaN(majorVersion)) { fullVersion = ''+parseFloat(navigator.appVersion); majorVersion = parseInt(navigator.appVersion,10); } if (majorVersion == 8) { // Return a custom amount for Safari 8: return $("#canvasBuilder").offset().left; } } // Return an amount for all other browsers: return 0; }
Then in your JavaScript you can do something like this:
pBucketHTML.css('left', e.pageX - returnSafariOffset() - (pBucketHTML.width() / 2));
Since you do not seem to get the same results as me, you may have to experiment with one form or another to get exactly what you are looking for. Let me know if you have any questions.
source share