2013-03-14 156 views
1

我正在使用Jquery來構建移動應用程序,我想顯示一個帶有大量文本的小彈出框。popup is 30% of the screen和我想要的文本將是scrollable帶手機小scrollerbar。Jquery帶小滾動條的彈出div像移動

這是我的彈出窗口:

<div id="popup" class= "DivWithScroll"> 
    <div class="txt"> 
     <p id="text"> textData...textData...textData</p> 
    </div> 
</div> 

試圖與這個CSS,但其windows scroller - 我不用什麼

.DivWithScroll{ 
    height:120px; 
    overflow:scroll; 
    overflow-x:hidden; 
} 

使用插件iscroll.js嘗試。看到一些例子,但沒有得到我想要的。

myScroll = new iScroll('popup'); 

有什麼想法嗎?

回答

1

我做了一個例子:

首先創建一個彈出窗口,並應用WebKit的滾動 風格:
http://css-tricks.com/custom-scrollbars-in-webkit/

試試看:

$(function(){ 
 
    
 
    // content of the pop up 
 
    var content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)."; 
 
    
 
    // add pop up to the window 
 
    $("body").append("<div id='PopUp'>" + content + "</div>"); 
 
    
 
    // css properties 
 
    $("#PopUp").css({ 
 
     "height":"300px", 
 
     "width":"300px", 
 
     "border":"1px solid #AAA", 
 
     "background-color":"#FFF", 
 
     "position":"fixed", 
 
     "top":"50%", 
 
     "left":"50%", 
 
     "margin-top":"-150px", 
 
     "margin-left":"-150px", 
 
     "overflow-y":"scroll" 
 
    }); 
 
});
::-webkit-scrollbar { 
 
    width: 12px; 
 
} 
 
    
 
::-webkit-scrollbar-track { 
 
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
 
    border-radius: 10px; 
 
} 
 
    
 
::-webkit-scrollbar-thumb { 
 
    border-radius: 10px; 
 
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>