Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible without using javascript?

I made a simple web UI with JSFiddle and I am wondering if the same UI can be made without using JavaScript.

A Fiddle says more than 1000 words.

So the question is (because it seems unclear for some people): How can I achieve the same results without using any JavaScript?

PS: I don't want to use JavaScript to re-calculate the position on every scroll event because the repositioning in IE is not smooth enough.

HTML:

<div class="A">
    <div class="B">
        B
    </div>

    <div class="C">
        This stays fixed when scrolling horizontally, but scrolls along when scrolling down the parent.
    </div>
</div>

CSS:

.A {
    background-color: yellow;
    height: 400px;
    width: 700px;
    overflow:scroll;
    position: relative;
}

.B {
    background-color: green;
    height: 1000px;
    width: 1500px;
    position: absolute;
    top:0;
    color:white;
}

.C {
    background-color: red;
    position: absolute;
    left: 100px;
    top: 0px;
    height: 1000px;
    width: 100px;
}

JS (with jQuery):

$('.A').scroll(function(e) {
    $('.C').css('left', e.target.scrollLeft + 100);
});
like image 373
Memet Olsen Avatar asked Aug 11 '14 15:08

Memet Olsen


People also ask

What happens without JavaScript?

The site provides functionality parity for noscript, but links to or redirects to a separate version of the site to achieve that. Site largely works without JavaScript, but some non-key features are unsupported or look broken.

Is it necessary to have JavaScript?

JavaScript has become integral to the Internet experience as developers build increased interaction and complexity into their applications. Search engines, ecommerce, content management systems, responsive design, social media and phone apps would not be possible without it.


1 Answers

When enough browsers support it, you will be able to use the new sticky position value:

.C {
    position: sticky;
    position: -webkit-sticky;
    left: 100px;
    top: auto; /* Default value */
}

http://jsfiddle.net/5z3nLqq5/12/

like image 149
Oriol Avatar answered Oct 21 '22 18:10

Oriol