Scrollable content by JavaScript

This is a scrollable content example created by JavaScript:

<html>
 
<head>
  <title>Scrollable Content</title>
</head>
 
<body>
 
<script type="text/javascript">
function up(){
    if(parseInt(document.getElementById("text").style.marginTop)-5>=parseInt("-"+document.getElementById("text").offsetHeight)+300){
        document.getElementById("text").style.marginTop = (parseInt(document.getElementById("text").style.marginTop)-5)+"px";
    }
}
 
function down(){
    if(parseInt(document.getElementById("text").style.marginTop)+5<=0){
        document.getElementById("text").style.marginTop = (parseInt(document.getElementById("text").style.marginTop)+5)+"px";
    }
}
</script>
 
<div id="scrollable_content" style="width: 300px; height: 300px; overflow: hidden; font-size: 15px; line-height: 15px;">
    <div id="text" style="margin-top: 0px;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br />Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br />Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
 
<div><img src="up.png" alt="up" style="cursor: pointer" onclick="up();" /> <img src="down.png" alt="down" style="cursor: pointer" onclick="down();" /></div>
 
</body>
 
</html>

Icons

  • Share/Bookmark
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

*





Info