I am in search of a unique way to move a DOM Object within another one on specific screen sizes. The idea stemmed from this insightful answer. While fixed widths are an option, my layout is flexible with LESS, so I aim to avoid using them as triggers. This lightweight method does not require additional libraries like require.js or modernizr to emulate media queries, making it ideal for my needs.
Currently, I am utilizing a bottom margin of 1px, but I find it unsatisfactory. I am on the lookout for an unconventional and senseless CSS value that can serve as a trigger. "move-to" in CSS3 seems promising, yet it remains a work in progress draft with no browser implementation noted. It does not even register in tools like Firebug.
This is my current approach:
CSS
@media screen and (min-width: 768px) {
.sidebar-secondary {
margin-bottom: 1px;
}
}
@media screen and (min-width: 992px) {
.sidebar-secondary {
margin-bottom: 0;
}
}
Javascript
var sidebar_move = function(){
if ( $(".sidebar-secondary").css("margin-bottom") === "1px") {
$(".sidebar-secondary").appendTo(".sidebar-primary");
}
}
window.setInterval(sidebar_move, 1000);
Any suggestions for a "nonsensical" CSS value I could utilize? Something obscure that people typically do not use. Ideally, it should be conflict-free and impervious to changes made by others, making margin a less than optimal solution.
Many advocate adding JavaScript code to enhance functionality, however, I am interested in understanding the rationale behind this viewpoint.
Additionally, I believe this method is more dependable than extracting window width through JavaScript, which explains the existence of complex scripts like equire.js. Or perhaps my understanding is flawed?
Is there a downside to linking JavaScript functions to CSS parameters? I intend to apply this concept solely for this purpose and nothing else.