A late answer but I came around with this and somehow I made a hack for this one.
The idea was to create an inner element which will hold the background-image and will act same as background-attachment:fixed
property.
Since this property makes the background image position relative to the window we have to move the inner element within it's container and this way we will get that effect.
var parallax_container = $(".parallax_container");
/*Create the background image holder*/
parallax_container.prepend("<div class='px_bg_holder'></div>");
$(".px_bg_holder").css({
"background-image" : parallax_container.css("background-image"), /*Get the background image from parent*/
"background-position" : "center center",
"background-repeat" : "no-repeat",
"background-size" : "cover",
"position" : "absolute",
"height" : $(window).height(), /*Make the element size same as window*/
"width" : $(window).width()
});
/*We will remove the background at all*/
parallax_container.css("background","none");
parallax_container.css("overflow","hidden");/*Don't display the inner element out of it's parent*/
$(window).scroll(function(){
var bg_pos = $(window).scrollTop() - $(".parallax_container").offset().top; /*Calculate the scrollTop of the inner element*/
$(".px_bg_holder").css({
"margin-top" : bg_pos+"px"
});
});
$(window).resize(function(){
$(".px_bg_holder").css({
"height" : $(window).height(),
"width" : $(window).width()
});
});