javascript - How to scroll content horizontally left or right when you swipe it with your finger -
i developing mobile application , want swipe image inside div
when user swipe finger, div
should scroll. here in example entire page scrolling scroll of div
. want div
scroll "http://smoothtouchscroll.com/" ` jquery smoothtouchscroll
<!-- css smooth touch scroll --> <link rel="stylesheet" type="text/css" href="../css/smoothtouchscroll.css" /> <!-- styles specific scrolling content --> <style type="text/css"> #touchscroller { top:70%; width:100%; height: 30%; /* position: relative; */ position:absolute; background-color:red; } /* replace last selector type(s) of element(s) have in scroller. if have images use #touchscroller div.scrollablearea img, if have div's use #touchscroller div.scrollablearea div, if have links use #touchscroller div.scrollablearea a, or add several selectors if have mixed content ...and on. */ #touchscroller div.scrollablearea { position: absolute; float: left; margin: 0; padding: 0 5px; /* if don't want images in scroller selectable, try following block of code. it's nice feature prevent images accidentally becoming selected/inverted when user interacts scroller. */ -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; overflow-x: scroll; overflow-y: hidden; white-space: nowrap; } </style> <!-- jquery - google api's --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!-- jquery ui - contains widget --> <script src="../js/jquery-ui-1.10.3.custom.min.js"></script> <!-- jquery kinetic --> <script src="../js/jquery.kinetic.min.js"></script> <!-- smooth touch scroll --> <script src="../js/jquery.smoothtouchscroll.min.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css"/> </head> <body> <p style="position:fixed"> welcome yourstory pvt ltd </p> <div id="touchscroller"> <a href="#"><img src="images/field.jpg" alt="demo image" id="field" style="left:0%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/gnome.jpg" alt="demo image" id="gnome" style="left:30%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/pencils.jpg" alt="demo image" id="pencils" style="left:60%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/golf.jpg" alt="demo image" id="golf" style="left:90%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/river.jpg" alt="demo image" id="river" style="left:120%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/train.jpg" alt="demo image" id="train" style="left:150%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/leaf.jpg" alt="demo image" id="leaf" style="left:180%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> <a href="#"><img src="images/dog.jpg" alt="demo image" id="dog" style="left:210%;width:30%;height:100%;position:absolute;background-size:100% 100%;"/></a> </div> <script> $(function() { $("#touchscroller").smoothtouchscroll({ continuousscrolling: true }); }); </script> </body>
`
first put <div id="touchscroller"> inside div ie <div class="sliderdiv"><div id="touchscroller"></div><div>. , place 'sliderdiv' per wish in page. , change style below mentioned . dont give touchscroller position absolute. #touchscroller { width: 100%; height: 330px; position: relative; background-color: red; } #touchscroller div.scrollablearea { position: relative; float: left; margin: 0; padding: 0 5px; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; overflow-x: scroll; overflow-y: hidden; white-space: nowrap; }
Comments
Post a Comment